1. 列表去重 li = [] for item in my_list: if item not in li: li.append(item) 2.集合去重 list(set(my_list)) 3.字典去重 dict1 = dict.fromkeys(my_list, '') li = dict1.keys…
1 a = [,,,,,,,,,,] a1 = [] for i in a: if i not a1: a1.append(i) else: continue 2 a = [,,,,,,,,,] a1 = set(a) 3 a = [,,,,,,,,,,] for i in a: : del a[a.index(i)] 4 import itertools a = [,,,,,,,] a1 = [] for i in itertools.groupby(a): a1.append(i)…
栗子: # 题目:将一个数组逆序输出. # # 程序分析:用第一个与最后一个交换. import random list =[random.randint(0,100) for _ in range(21)] print(list) #数应该先排序 def bubbleSort(arr): for i in range(1, len(arr)): for j in range(0, len(arr)-i): if arr[j] > arr[j+1]: arr[j], arr[j + 1] = a…