Index all *except* one item in python

前端 未结 9 1089
清酒与你
清酒与你 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-29 00:00

    If you don't know the index beforehand here is a function that will work

    def reverse_index(l, index):
        try:
            l.pop(index)
            return l
        except IndexError:
            return False
    

提交回复
热议问题