二维列表降成一维列表:
from tkinter import _flatten
A = [[1,2],[3],[4,5],[6],[7]]
B= list(_flatten(A))
#输出 B = [1, 2, 3, 4, 5, 6, 7]
整数列表与字符串列表互相转换:
B = [1, 2, 3, 4, 5, 6, 7]
C = list(map(str,B))
#输出:C = ['1','2','3','4','5','6','7']
D = list(map(int,C))
#输出 D = [1, 2, 3, 4, 5, 6, 7]
判断列表D中是否包含列表E中所有的元素:
D = [1, 2, 3, 4, 5, 6, 7]
E = [5, 6, 7]
set(D)>set(E)
#输出: True
判断列表F中的元素是否在D中,若不在,打印出元素
D = [1, 2, 3, 4, 5, 6, 7]
F = [0, 5, 7, 9]
for f in F:
if f not in D:
print(f, ' not in D')
#输出:
#0 not in D
#9 not in D