Assuming I have a tuple like:
[(\'text-1\',\'xxx\'), (\'img-1\',\'iii\'), (\'img-2\',\'jjj\'), (\'text-2\',\'xxx\')]
I want to filter out t
With Normal Loop
input = [('text-1','xxx'), ('img-1','iii'), ('img-2','jjj'), ('text-2','xxx')]
inp = []
for i in input:
if 'img' in i[0]:
inp.append(i)
print(inp)
or by Using lambda function
inp = list(filter(lambda x: 'img' in x[0],input))
print(inp)
or by Using List Comprehension
inp = [i for i in input if 'img' in i[0]]
print(inp)