![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 l1 = [1, 2, 3, 4, 2, 2, 3, 4, 55, 66] 2 l2 = list() 3 # [元素,‘次数’,元素,‘次数’。。。] 4 for i in l1: 5 if i not in l2: 6 #不存在就把元素和1放进去 7 l2.append(i) 8 l2.append(str(1)) 9 else: 10 #存在就把次数加1 11 l2[l2.index(i) + 1] = str(int(l2[l2.index(i) + 1]) + 1) 12 print(l2) 13 i = 0 14 while i < len(l2): 15 print(l2[i], l2[i + 1], sep='---') 16 i += 2