标签:isp control col lambda split() and 字符串 controls set
s = ‘i am very very like you and like you‘ dict( [(i, s.split().count(i)) for i in s.split()] ) Out[2]: {‘i‘: 1, ‘am‘: 1, ‘very‘: 2, ‘like‘: 2, ‘you‘: 2, ‘and‘: 1}
set( map(lambda x:(x, s.split().count(x)), s.split()) ) Out[6]: {(‘am‘, 1), (‘and‘, 1), (‘i‘, 1), (‘like‘, 2), (‘very‘, 2), (‘you‘, 2)}
dict( map(lambda x:(x, s.split().count(x)), s.split()) ) Out[7]: {‘i‘: 1, ‘am‘: 1, ‘very‘: 2, ‘like‘: 2, ‘you‘: 2, ‘and‘: 1}
标签:isp control col lambda split() and 字符串 controls set
原文地址:https://www.cnblogs.com/douzujun/p/12368652.html