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设计】。

相关文章

Python实现将通信达.day文件读取为DataFrame

如下所示: import os import struct import pandas as pd def readTdxLdayFile(fname="C:\\TdxW_HuaT...

python可视化实现KNN算法

python可视化实现KNN算法

简介 这里通过python的绘图工具Matplotlib包可视化实现机器学习中的KNN算法。 需要提前安装python的Numpy和Matplotlib包。 KNN–最近邻分类...

python类的继承实例详解

python 类的继承 对于许多文章讲解python类的继承,大多数都是说一些什么oop,多态等概念,我认为这样可能对有一定基础的开发者帮助不是那么大,不如直接用在各种情况下所写的代码,...

python-numpy-指数分布实例详解

如下所示: # Seed random number generator np.random.seed(42) # Compute mean no-hitter time: ta...

Python标准库urllib2的一些使用细节总结

Python 标准库中有很多实用的工具类,但是在具体使用时,标准库文档上对使用细节描述的并不清楚,比如 urllib2 这个 HTTP 客户端库。这里总结了一些 urllib2 的使用细...