python-str,list,set间的转换实例

yipeiwu_com6年前Python基础

实例如下:

a = '123abbcc!@#' 
b = ['1', '2', '3', 'a', 'b', 'c', '!', '@', '#']
c = set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2']) 

str -> list:list(a) 
result : ['1', '2', '3', 'a', 'b','b', 'c','c','!', '@', '#']
list -> str : ''.join(list) 
result : 123abc!@#

str -> set : set(a)
result : set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2']) set类型是无序不重复的
set -> str :  ''.join(c) 
result: a!cb@#132

set -> list : list(c)
result : ['a', '!', 'c', 'b', '@', '#', '1', '3', '2']
list -> set : set(b)
result : set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2'])

以上这篇python-str,list,set间的转换实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Numpy数组array和矩阵matrix转换方法

1、ndarray转换成matrix import numpy as np from numpy import random,mat r_arr=random.rand(4,4)...

Python实现微信公众平台自定义菜单实例

首先先获取access_token,并保存与全局之中 def token(requset): url = 'https://api.weixin.qq.com/cgi-bin/...

解决pycharm remote deployment 配置的问题

解决pycharm remote deployment 配置的问题

(1)无法完整识别服务器端的环境变量 举例: a: shell下 b:win7下使用pycharm 结果发现对应的环境变量值缺失 如此会影响一些模块的正常加载(如cx_Oracle需...

Django自带的加密算法及加密模块详解

Django 内置的User类提供了用户密码的存储、验证、修改等功能,可以很方便你的给用户提供密码服务。 默认的Ddjango使用pbkdf2_sha256方式来存储和管理用的密码,当然...

Pytorch提取模型特征向量保存至csv的例子

Pytorch提取模型特征向量 # -*- coding: utf-8 -*- """ dj """ import torch import torch.nn as nn impor...