#去重 A = ['geovindu','刘杰','江山','河水','刘杰','geovindu','张三','李五'] B = [] for i in A: if i not in B: B.append(i) print(B) C = set(A) print(list(C)) # 移动位置 从index=3 要移的index 指定的位置index 1 index=1 #新位置 oldindex=3 #旧位置 show = ['2A', '3B', '1C', '4E', '5A'] temp = show[oldindex] for k in range(oldindex, index, -1): #移到index 1 show[k] = show[k - 1] show[index] = temp print(show) print('*********') #移到index 0 index=0 #新位置 oldindex=3 #旧位置 show = ['2A', '3B', '1C', '4E', '5A'] temp = show[oldindex] for k in range(oldindex,index, -1): show[k] = show[k - 1] show[index] = temp print(show) print('*********') # 移除 wait = [3001, 4001, 5001, 2001, 2002, 3002, 2003, 4002, 2004, 2005] delindex = 2 #位置 for k in range(delindex, len(wait) - 1): wait[k] = wait[k + 1] wait[len(wait) - 1] = 0 print(wait) print('*********') # 添加一个 添加位置 index 4 index=4 #新位置 wait = [3001, 4001, 5001, 2001, 2002, 3002, 2003, 4002, 2004, 2005] wait = wait + [0] for k in range(len(wait) - 1, index, -1): wait[k] = wait[k - 1] wait[index] = 9001 print(wait) print('*********') # 添加一个 添加位置index 3 eca = ["Tony", "Paul", "Kelly", "Wendy", "Jack"] eca = eca + [''] index=3 #新位置 nn = len(eca); for k in range(nn - 1, index, -1): eca[k] = eca[k - 1] eca[index] = "viky" print(eca)
标签:index,eca,show,python,list,oldindex,print,wait From: https://www.cnblogs.com/geovindu/p/18287624