data = [(1,'hi'),(2,'hello'),(3,'hi'),(4,'hi'),(5,'hello'),(6,'hello'),
(7,'hi'),(8,'hello')]
new_data = []
for i in data:
if i[1] == 'hi':
new_data.append(i)
print(new_data)
output:[(1, 'hi'), (3, 'hi'), (4, 'hi'), (7, 'hi')]
i am a beginner in python. i want the same output but want to reduce the amount of code in the'For' loop and be more efficient.