有没有办法计算名单上的人数?你知道吗
下面的示例是使用count()方法编写的。你知道吗
然后,结果应该与字典的输出相同。你知道吗
Attention: do not use built-in count() method and should return a dictionary. If the list is empty, it will return an empty dictionary.
a=['Mary', 'David','Grace','Curtis','Alice','Joe','Grace']
# use count
print(dict(map(lambda x : (x , list(a).count(x)) , a)))
output: {'Mary': 1, 'David': 1, 'Grace': 2, 'Curtis': 1, 'Alice': 1, 'Joe': 1}
相关问题 更多 >
编程相关推荐