在 python 中将字符串转换为列表。
最编程
2024-06-07 16:03:43
...
1.str >>>list
str1 = "12345"
list1 = list(str1)
print list1
str2 = "123 sjhid dhi"
list2 = str2.split() #or list2 = str2.split(" ")
print list2
str3 = "www.google.com"
list3 = str3.split(".")
print list3
输出为:
['1', '2', '3', '4', '5']
['123', 'sjhid', 'dhi']
['www', 'google', 'com']
3.list >>>str
str4 = "".join(list3)
print str4
str5 = ".".join(list3)
print str5
str6 = " ".join(list3)
print str6
wwwgooglecom
www.google.com
www google com
参考链接:
http://blog.****.net/cnm****456/article/details/27830671
http://piziyin.blog.51cto.com/2391349/568426
推荐阅读
-
在Python 3中玩转 bytes 和 str:基础用法、不同编码间的转换以及列表、元组与字符串之间的互变技巧
-
在 vue 中将不规则的 json 转换为对象,或将对象转换为 json 字符串。
-
在 Java 中将 map.values 转换为列表或字符串[]
-
在 GO 中将地图转换为列表的通用函数
-
请求在 python 中将 map 转换为 list、set 和 tupleEN
-
要求在 Netlogo EN 中将字符串转换为变量名
-
在 python 中将字符串转换为列表。
-
将 Python 列表的字符串形式快速转换为列表形式的 4 种方法
-
在 PHP 中将所有字符串转换为小写或大写字母
-
要求在 Python EN 中将 XYZ 坐标转换为经度/纬度