Remove list element without mutation

后端 未结 6 1399
无人及你
无人及你 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条回答
  •  长发绾君心
    2021-02-05 00:29

    There is a simple way to do that using built-in function :filter .

    Here is ax example:

    a = [1, 2, 3, 4]
    b = filter(lambda x: x != 3, a)
    

提交回复
热议问题