Remove list element without mutation

后端 未结 6 1383
无人及你
无人及你 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:34

    If the order is unimportant, you can use set (besides, the removal seems to be fast in sets):

    list(set(m) - set(['a']))
    

提交回复
热议问题