List comprehension from multiple sources in Python?
- by Noah
Is it possible to replace the following with a list comprehension?
res = []
for a, _, c in myList:
for i in c:
res.append((a, i))
For example:
# Input
myList = [("Foo", None, [1, 2, 3]), ("Bar", None, ["i", "j"])]
# Output
res = [("Foo", 1), ("Foo", 2), ("Foo", 3), ("Bar", "i"), ("Bar", "j")]