[Solved] Get the first word and second word using list comprehensions [closed]


You can use zip to process two lists in parallel. Zip will stop iteration at the shorter of the two lists.

mashemup = [x.split()[0] + ' ' +  y.split()[1] for x, y in zip(meeps, peeps)]
print(mashempup)

['Foghorn Cleese', 'Elmer Palin', 'Road Gilliam', 'Bugs Jones', 'Daffy Chapman', 'Tasmanian Idle']

Or if you need a list of tuples:

mashemup = [(x.split()[0], y.split()[1]) for x, y in zip(meeps, peeps)]
print(mashempup)

[('Foghorn', 'Cleese'), ('Elmer', 'Palin'), ('Road', 'Gilliam'), ('Bugs', 'Jones'), ('Daffy', 'Chapman'), ('Tasmanian', 'Idle')]

solved Get the first word and second word using list comprehensions [closed]