Dec-17-2020, 08:16 PM
well, you don't need the list comprehension at all. it just creates the same list as the original.
world_cup_winners = [[2006, "Italy"], [2010, "Spain"], [2014, "Germany"], [2018, "France"]] for item in world_cup_winners: print(*item, sep=' ')frankly, given that you know the sub-lists are 2-element in the format year, winner it may be more readable to write it like this
world_cup_winners = [[2006, "Italy"], [2010, "Spain"], [2014, "Germany"], [2018, "France"]] for year, winner in world_cup_winners: print(f'{year} {winner}')I really hope the book does not suggest something like this, just to use list comprehension
world_cup_winners = [[2006, "Italy"], [2010, "Spain"], [2014, "Germany"], [2018, "France"]] [print(*item, sep=' ') for item in world_cup_winners]It's really ugly and abuse of side effects using list comprehension.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs