Index all *except* one item in python

前端 未结 9 1084
清酒与你
清酒与你 2020-11-28 23:45

Is there a simple way to index all elements of a list (or array, or whatever) except for a particular index? E.g.,

  • mylist[3]

9条回答
  •  情话喂你
    2020-11-28 23:58

    If you want to cut out the last or the first do this:

    list = ["This", "is", "a", "list"]
    listnolast = list[:-1]
    listnofirst = list[1:]
    
    

    If you change 1 to 2 the first 2 characters will be removed not the second. Hope this still helps!

提交回复
热议问题