Remove list element without mutation

后端 未结 6 1373
无人及你
无人及你 2021-02-04 23:36

Assume you have a list

>>> m = [\'a\',\'b\',\'c\']

I\'d like to make a new list n that has everything except for a given

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 00:14

    Another approach to list comprehension is numpy:

    >>> import numpy
    >>> a = [1, 2, 3, 4]
    >>> list(numpy.remove(a, a.index(3)))
    [1, 2, 4]
    

提交回复
热议问题