Student Login

Grok this function to level up your Python

Look at this code:

  1. def itemgetter(key):
  2. def get_item(dictionary):
  3. return dictionary[key]
  4. return get_item

If you'd like to level up your Python... this is a great function to understand.

I'm not even claiming you will write functions like this very often. (Though I do myself, sometimes.) But in order to understand what this function does, you have to grok a few Python pieces people normally don't grok.

Such as:

And when you grok all these grokkables...

What happens?

By the way, you use it like this:

  1. codes = {"a": 7, "b": 3, "c": 2}
  2. get_a = itemgetter("a")
  3. print(get_a(codes))

What happens when you grok all these points is this:

You can't help but level up as a dev using Python...

Standing out from the other, un-grokking Python devs.

So get grokking.

For Teams Bootcamp