栗子: # 题目:将一个数组逆序输出. # # 程序分析:用第一个与最后一个交换. 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…
1)%格式化方法 >>> a = "this is %s %s" % ("my", "apple") >>> a 'this is my apple' 2)内置方法format(): >>> a = "this is {} {}".format("apple","my") >>> a 'this is apple m…
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…