1.列表合并保留最大长度
import itertools
w, x, y, z = [], [1], [2, 3], [4, 5, 6]
longest_wxyz = itertools.zip_longest...y, z)
print(list(longest_wxyz))
结果: [(None, 1, 2, 4), (None, None, 3, 5), (None, None, None, 6)]
2.列表元素替换...,'1','4']
t=list(set(t))
print(t)
结果: ['China', '4', '中国', '8', '1', '7', '2']
如果既想实现去重,又能保持原有的顺序,可以使用下面的方法...xt=urn:btih:060C0CE5CFAE29A48102280B88943880689859FC']
8.字符串和列表互相转换
字符串转为列表
str1 = 'a1b2' ls1 = [str(...i) for i in str1]
列表转为字符串
ls2 = ['1','a','2','b'] str2 = ''.join(ls2)
同步遍历多个列表
使用zip()函数
name_list =