Skip to content

Instantly share code, notes, and snippets.

@saevarb
Created July 17, 2017 22:16
Show Gist options
  • Save saevarb/8e1292b19a6dd7b5739770cb24c722aa to your computer and use it in GitHub Desktop.
Save saevarb/8e1292b19a6dd7b5739770cb24c722aa to your computer and use it in GitHub Desktop.
def longest(input_string):
# no need for the type check.
# str is built-in. use another name(and use the right variable)
longest_len = 0
words = input_string.split()
longest = ''
for word in words:
if len(word) > len(longest):
longest = word
return longest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment