zoukankan      html  css  js  c++  java
  • 几个基础 类型循环删除

    lst = ['周老二', '周星星', '麻花藤', '周扒皮']
    for i in range(len(lst)-1,-1,-1):
            lst.pop(i)
    print(lst)
     直接删空
    for i in range(len(lst)-1,-1,-1):
            lst.remove(lst[i])
    print(lst)
    直接删空
    lst = ['周老二', '周星星', '麻花藤', '周扒皮']
    for i in range(len(lst)):
        lst.remove(lst[i])
    print(lst)     # 报错:IndexError: list index out of range
    
    
    
     
    lst = ['周老二', '周星星', '麻花藤', '周扒皮']
    for i in range(len(lst)-1,-1,-1):
        if lst[i][0] =='':
            lst.remove(lst[i])
    print(lst)
    删除姓周的
    lst = ['周老二', '周星星', '麻花藤', '周扒皮']
    for i in range(len(lst)-1,-1,-1):
        if lst[i][0] =='':
            lst.pop(i)
    print(lst)
    lst = ['周老二', '周星星', '麻花藤', '周扒皮']
    lst1=[]
    for i in lst:
        if i.startswith(''):
            lst1.append(i)
    for j in lst1:
            lst.remove(j)
    print(lst)
    删除 周
    第一
    lst = ['周老二', '周星星', '麻花藤', '周扒皮']
    for i in range(len(lst)):
        lst.pop()
    print(lst)
    第二
    li=[]
    for e in lst:
        li.append(e)
    for e in li:
        lst.remove(e)
    print(lst)
  • 相关阅读:
    python基础学习1-函数相关
    python基础学习1-SET 集合
    Linux命令学习笔记1
    python基础学习1-字典的使用
    python基础学习1-列表使用
    Jzoj4743 积木
    Jzoj4786 小a的强迫症
    Jzoj4746 树塔狂想曲
    Jzoj5246 Trip
    Jzoj5245 Competing Souls
  • 原文地址:https://www.cnblogs.com/LMTlmt/p/10239573.html
Copyright © 2011-2022 走看看