码迷,mamicode.com
首页 > 编程语言 > 详细

python list删除数据 和复制 列表

时间:2017-10-28 17:43:25      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:获得   other   bsp   授权   python3   not   .com   for   class   

复制列表的方法:

  

lst = [1,2,3] 
lst1 = lst[:] # one way 
lst2 = list(lst) # another 

删除数据的正确方法:

num_list = [1, 2, 3, 4, 5] 
print(num_list) 
for item in num_list[:]: 
    if item == 2: num_list.remove(item) 
    else: 
        print(item) 
print(num_list)

作者:方小圆
链接:https://www.zhihu.com/question/49098374/answer/152953958
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


 

python list删除数据 和复制 列表

标签:获得   other   bsp   授权   python3   not   .com   for   class   

原文地址:http://www.cnblogs.com/xqnq2007/p/7747233.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!