Created
February 1, 2017 03:19
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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