列表处理

列表中的数字元素的计数

from collections import Counter
word_list=[1,1,1,2,2,3,3,3,3,6,6,5,6,8,23,]
result= dict(Counter(word_list))
print(result)
结果:
{1: 3, 2: 2, 3: 4, 6: 3, 5: 1, 8: 1, 23: 1}

两个列表合并

l1=[1,2,3]
l2=['萝卜','白菜','火龙果']
print(dict(map(lambda x,y:[x,y], l1,l2)))
结果:
{1: '萝卜', 2: '白菜', 3: '火龙果'}

猜你喜欢

转载自www.cnblogs.com/hehedaaa/p/8921348.html