Yesterday, I shared a quick Python tip about for-loops versus list comprehensions.
Today, I created another infographic about list comprehensions (listcomps). Listcomps provide a readable alternative to map/filter comprehensions. As you can see from the infographic, the listcomp syntax is shorter and easier to understand.
This syntax isn't limited to lists either.
You can do dict and set comprehensions too
Here's a short example of a dict comprehension:
country_codes = [
("United Kingdom", 44),
("United States", 1),
("Mexico", 52),
("Australia", 61),
]
code_to_country = {code: country for country, code in country_codes}
The tools I use to create the infographic
- I use Showcode to generate the code images
- An alternative you can use https://carbon.now.sh/
- I stitch everything together using Canva
- I use the Dracula color palette
- If you want to include free usable images, you can use unsplash.
And that's it! I encourage you to start creating your own infographic!
Thanks for reading! Let me know if you have any feedback.
Top comments (0)