Removing an item from a list of lists based on each of the lists first element

后端 未结 4 2026
鱼传尺愫
鱼传尺愫 2020-12-03 23:44

Given:

a = [[1,2],[3,4],[5,6],[7,8]]
b = 3

I would like to remove an item of a that has b as it\'s first item. S

4条回答
  •  孤街浪徒
    2020-12-04 00:16

    If your list are small then you are also try filter ,

    a = [[1,2],[3,4],[5,6],[7,8]]
    b = 3
    
    print(list(filter(lambda x:x[0]!=b,a)))
    

    output:

    [[1, 2], [5, 6], [7, 8]]
    

提交回复
热议问题