Sign Up Now!

Sign up and get personalized intelligence briefing delivered daily.


Sign Up

Articles related to "range"


Python built-ins worth learning

  • Similar to like list and tuple, the dict function is equivalent to looping over an iterable of key-value pairs and making a dictionary from them.
  • If enumerate is news to you (or if you often use range(len(...))), see my article on looping with indexes in Python.
  • By the way, if you need to use zip on iterables of different lengths, you may want to look up itertools.zip_longest in the Python standard library.
  • Unlike the numbers[::-1] slice syntax, reversed(numbers) doesn’t build up a whole new list: the lazy iterator it returns retrieves the next item in reverse as we loop.
  • The sorted function, like min and max, compares the items given to it by using the < operator, so all values given to it need so to be orderable.

save | comments | report | share on