mylist = [2, "hello", "老鸟", "python", "老鸟python", "hello", 2, "hello", "python", 2] mydict = dict.fromkeys(mylist,0) for i in mylist: if i in mydict: mydict[i] += 1 print(mydict)
mylist = [2, "hello", "老鸟", "python", "老鸟python", "hello", 2, "hello", "python", 2] mydict = dict.fromkeys(mylist,0) for i in mylist: if i in mydict: mydict[i] += 1 print(mydict)