中国空间站图片绘画,网易邮箱能登企业邮箱吗,网站代理浏览器插件,成都网站建设 公司增加 # append 在已有的列表末尾插入一个值
list1[张三,李四]
list1.append(王二)
print(list1)# expand 在已有的列表末尾追加一个列表
list1 [love,peace,keep]
list2 [beautiful,string]
list1.extend(list2)
print(list1)# insert 在指定位置插入一个值list1 [love,peac…增加
# append 在已有的列表末尾插入一个值
list1[张三,李四]
list1.append(王二)
print(list1)# expand 在已有的列表末尾追加一个列表
list1 [love,peace,keep]
list2 [beautiful,string]
list1.extend(list2)
print(list1)# insert 在指定位置插入一个值list1 [love,peace,keep]
list1.insert(1,wish)
print(list1)
删除 # del根据索引值删除元素
lang [Python, C, Java, PHP, Ruby, MATLAB]
#使用正数索引
del lang[2]
print(lang)
del lang[1:4]
print(lang)# pop 根据索引值删除元素,默认删除最后一个元素
nums [40, 36, 89, 2, 36, 100, 7]
nums.pop(0)
print(nums)
print(nums.pop())
print(nums)# 根据元素值进行删除
nums [40, 36, 89, 2, 36, 100, 7]
#第一次删除36
nums.remove(36)
print(nums)# 删除所有元素
nums.clear()
print(nums)
index # 从列表中获取指定索引元素的第一个匹配位置
# index
# 定义列表
list1 [hello, world, welcome, to, our, world]
w_index list1.index(world)
print(第一个匹配world的位置为, w_index)wel_index list1.index(welcome)
print(第一个匹配welcome的位置为, wel_index)wor_index list1.index(world, 2) # 从21的位置开始索引
print(从第3个位置开始索引第一个匹配world的位置为, wor_index)wel_index2 list1.index(welcome, 1, 4)
print(第一个匹配welcome的位置为, wel_index2)
排序
# list.sort(key,reverse) reverseTrue 降序排列reverseFalse 为升序
list2 [(2, 3), (3, 1), (4, 3), (1, 2), (2, 1)]
list2.sort()
print(list2升序之后为, list2)# 2指定排序方式
# 实例③ 指定降序排序
list3 list2.copy()
list3.sort(reverseTrue)
print(list3降序之后为, list3)# 与lambda函数结合使用list1 [(2, 3), (3, 1), (4, 3), (1, 2), (2, 1)]
list1.sort(keylambda x: x[1])
print(list1按照第二个元素升序之后为, list1)# 实例②
list2 list1.copy()
list2.sort(keylambda x: x[1], reverseTrue)
print(list2按照第二个元素降序之后为, list2)