一道有关Python的 自己能力有限 希望大家可以探讨探讨,学习学习~~
就是根据元组生成字典,键是元组的元素,值是键在元组中出现的次数:
tuplex=('a','b','c','a','b','d','a') output={i:tuplex.count(i) for i in tuplex} print(output)
结果:
{'a': 3, 'b': 2, 'c': 1, 'd': 1}