the_list = ['Antonia', 'Sara', 'Nick', 'Deppy', 'Antonia', 'Deppy', 'Antonia']
# count unique item in the list 'the_list'
for item in set(the_list):
print(item, ':', the_list.count(item))
# an ordered new list containing unique item of 'the_list'
new_list = sorted([item for item in set(the_list)])
print(new_list)
Outputs:
Nick : 1
Antonia : 3
Sara : 1
Deppy : 2
['Antonia', 'Deppy', 'Nick', 'Sara']
有很多方法可以实现你的目标。以下是一个简单的方法:
相关问题 更多 >
编程相关推荐