a = "chocolate" b = list(a) for i in range(len(b)): c = 0 for j in range(len(b)): if b[i] == b[j]: c += 1 print(b[i],c) i did this, it counted the elements but printed the elements twice i also wanted to find the duplicates location in the string like c = ...
最后,我们打印完全初始化的列表。 lis1=[]print("Contents of the list before initialisation:",str(lis1))char1="A"forcharactersinrange(0,26):lis1.append(char1)char1=chr(ord(char1)+1)print("Contents of the list after initialisation:",str(lis1)) Python Copy 输出 Contentsof thelistb...