a = [
'a,1',
'b,3,22',
'c,3,4',
]
b = [
'a,2',
'b,1',
'd,5',
]
c=['a,1,2', 'b,3,22,1', 'c,3,4', '5']
dic=dict([(i[0],i) for i in a]) print(dic) # 組成元組形式,而後生成字典形式 for v in b: if dic.get(v[0]): dic[v[0]]=dic[v[0]]+v[1:] else: dic[v[0]]=v[2:] print(list(dic.values()))
lst = [1,2,4,8,16,32,64,128,256,512,1024,32769,65536,4294967296]
dic={}
for item in lst:
l_len=len(str(item))
dic.setdefault(l_len,[]).append(item)
print(dic.setdefault(l_len,[]),type(dic.setdefault(l_len,[]))) # <class 'list'>
print(dic)
lis = [2,4,5,6,7] for i in lis: if i % 2==0: lis.remove(i) print(lis)
### [4, 5, 7]
remove() 函數用於移除列表中某個值的第一個匹配項。app
remove()方法語法:函數
list.remove(obj)