Это может быть достигнуто различными способами:
Здесь я даю вам два способа сделать это.
1-й и самый простой способ - сохранить счетчик и проверить счетчик.,Это может быть достигнуто, как показано ниже:
counter_three = 0
counter_not_three = 0
for two in one:
if two.text=='three':
if counter_three == 0:
counter_three = counter_three + 1
print('Hello')
else:
if counter_not_three == 0:
print('Bye')
counter_not_three = counter_not_three + 1
2-й способ, как показано ниже:
a = [{"text": "three"},{"text": "three"}, {"text": "three"}, {"text": "three"}, {"text": "two"}]
a_list = set(map(lambda x: x["text"], a))
for x in a_set:
if x == 'three':
print('Hello')
else:
print('Bye')