Skip to content

Instantly share code, notes, and snippets.

@augustogoulart
Created July 20, 2017 20:03
Show Gist options
  • Save augustogoulart/1cb90ca768e6b14c93825e1269f27d55 to your computer and use it in GitHub Desktop.
Save augustogoulart/1cb90ca768e6b14c93825e1269f27d55 to your computer and use it in GitHub Desktop.
Extending Python's dictionary
class LongNameDict(dict):
def longest_value(self):
longest = None
for key, value in self.items():
if not longest or len(value) > len(longest):
longest = value
return longest
names = LongNameDict(first='josé', second='schwarzenegger')
assert names.longest_value() == 'schwarzenegger'
assert not names.longest_value() == 'josé'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment