A nice skill to discuss. Excellent choice of article content and clear explanation
Nice list. I once used comprehension to divide a list into smaller groups. For example:
>>> source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
>>> [source[i:min(i + group_size, len(source))] for i in range(0, len(source), group_size)]
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13]]
Totally agree with you on that list comprehensions work faster than traditional loops. Generally, if we write more pythonic code, it will always be more time-efficient I think.
Nice write up. 😀
Don't you think, the heading "Convert dollars to euros" should actually be "Convert euros to dollars".
Moreover the function name is also convert_to_dol().
Super cool post. List comprehensions are very useful. I've got some alternate solutions to make life harder.




Use map(Callable, Iterable)

This is a great resource, thank you for writing it. I'll be adding it to my list of extra reading for my class.
The solutions for the practice ideas:
[(model, color, size) for model in models for color in colors for size in sizes]
princesses_from_frozen = [frozen_char for frozen_char in frozen for princess in princesses for i_like in princesses_i_like if frozen_char == princess and frozen_char == i_like]
[F"{name} {surname} - {age}" for name, surname, age in zip(names, surnames, ages) if int(age) > 20]
Brian Ketelboeter
I code to live
it is a small thing, but you sometimes use 'array' (non-python) when you mean 'list' (python). Again, very small.