How I can convert this code to one line?
target = 3
res = None
for x, y in [(1, 2), (3, 4), (5, 6)]:
if x == target:
res = y
break
Surely I can use list comprehensive but it's doesn't have a break
statement
I tried: this solution and a such code:
res = iter(lambda x=iter([(1, 2), (3, 4), (5, 6)]): next(x), (1, 2))
next(res) # StopIteration
But both are failed