List comprehensions Python

All, Tips

I think one of the most beautiful things and also powerful are the list compreehensions, which makes the language quite interesting.

The syntax is quite simple:

[ expression for item in list if conditional ]

The tutorial [1] explains specifically how to do it. I confess it’s not easy to take it at first try. You can also use directly from the source [3].

But when you learn it, you will want to use all over your code. EVEN WHEN YOU SHOULDN’T!

In some cases, when you dont need a list actually, its better to use a simple NEXT() function[2].






Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s