""" 查 """ list1=[1,2,3,44,5,2,44] print(list1) print(len(list1)) print(list1.count(2))#元素的出现次数 print(max(list1)) print(min(list1)) print("++++++++++++++++++++++++++++") print(list1.index(44)) print(list1.index(44,4))
""" 列表的排序sort """ list1 = [99,2,3,48,20,10,30,3] print(list1) list1.sort()#根据天然升序顺序排序 print(list1) list1.sort(reverse=True)#按照天然降序排序 print(list1) print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++") names=["like","qq","alike","killer","hiradateddd","a"] print(names) names.sort() print(names) names.sort(reverse=True) print(names) names.sort(key=len)#根据字符串长度来排序 print(names) names.sort(key=len,reverse=True) print(names)
""" 0---len-1 """ list1=[1,2,3,4,5] print(list1) for ele in list1: print(ele,end=",") print() print("++++++++++++++++++++++++++++") for i in range(len(list1)): print(i,end="----") print(list1[i],end=",") print() print("=====================") #在一个列表中寻找一个key的位置 key=3 for i in range(len(list1)): if list1[i]==key: print(i)
""" 反向 """ for i in range(-1,-5,-1): print(i,end=",") print() print("+++++++++++++++++++") for i in range(5,-1,-1): print(i,end=",") print("") print("++++++++++++++++++++++") list1=[1,2,3,4,5] for i in range(-1,-len(list1)-1,-1): print(list1[i],end=",") print() print() for i in range(len(list1)-1,-1,-1): print(list1[i],end=",")