Good evening!

Here’s another quick Python tip for you. Did you know that you could order tuples and lists in Python?

>> (1,2,3) < (2,2,3)

Yeah, essentially, it just compares them element by element until it encounters elements that are not equal. I encourage you to experiment further: with different lengths and element combinations.

And you know what, namedtuple has the same property! For example, I had a namedtuple that had time and coordinates.

Coord = namedtuple('Coord', ('time', 'lat', 'lng'))

And at some point I needed it to be sorted in a list by time. Moreover, I used bisect module to insert datablocks into the list so the order by time would be preserved. Since 'time' is the first element in this tuple, it gets compared first, just like in the example above. So I didn’t need to perform any actions or tamper with __eq__, __lt__ or __gt__, as I initially thought. Useful! Of course, if two datablocks have the same time, they will be sorted by latitude, but that was not my concern. I didn’t expect any datablocks with the same time anyway.

This is just a quick tip for you. And a good reason to consider namedtuple instead of a dict in situations like this one.

Stay tuned! I’ll see you eventually!