Skip to content

Instantly share code, notes, and snippets.

@Codehunter-py
Last active May 30, 2022 10:13
Show Gist options
  • Save Codehunter-py/e7ee9c49a95cf0fa965fd70562b8cbe8 to your computer and use it in GitHub Desktop.
Save Codehunter-py/e7ee9c49a95cf0fa965fd70562b8cbe8 to your computer and use it in GitHub Desktop.
The long_words function returns all words that are at least 7 characters. Fill in the regular expression to complete this function.
import re
def long_words(text):
pattern = r"\w{7,}"
result = re.findall(pattern, text)
return result
print(long_words("I like to drink coffee in the morning.")) # ['morning']
print(long_words("I also have a taste for hot chocolate in the afternoon.")) # ['chocolate', 'afternoon']
print(long_words("I never drink tea late at night.")) # []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment