Skip to content

Instantly share code, notes, and snippets.

@shamikalashawn
Created February 1, 2017 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shamikalashawn/6628bd1fb62234a7851d855bbb03234d to your computer and use it in GitHub Desktop.
Save shamikalashawn/6628bd1fb62234a7851d855bbb03234d to your computer and use it in GitHub Desktop.
Give me a dictionary and I'll give you the longest key in that dictionary.
def longest_key(a_dict):
if a_dict == {}:
return None
else:
longestkey = ''
for key in a_dict:
if len(key) > len(longestkey):
longestkey = key
return longestkey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment