Tag: iterables

Enumerate your iterables!

Enumerate your iterables!

Whenever you write code similar to the following:

you should consider making your code a bit more Python by using the builtin enumerate  function:

The enumerate  function takes an iterable and an optional parameter start  (defaulting to 0). The return value is a tuple containing the index of the element and the element …

+ Read More

Build your lists using list comprehensions

Build your lists using list comprehensions

A common way to build lists in a program that we see is this construct

The basic construct here is that by looping over something (an iterable or a condition) we add items to our list. I’m sure you’ve been there and have already used this construct in some of your code. There is …

+ Read More