Finding in elements in a tuple and filtering them

后端 未结 5 2074
借酒劲吻你
借酒劲吻你 2020-11-30 10:23

Assuming I have a tuple like:

[(\'text-1\',\'xxx\'), (\'img-1\',\'iii\'), (\'img-2\',\'jjj\'), (\'text-2\',\'xxx\')]

I want to filter out t

5条回答
  •  醉酒成梦
    2020-11-30 11:00

    Something like this perhaps?

    l2 = [item for item in l1 if item[0].startswith('img')]
    

提交回复
热议问题