Created
December 26, 2018 23:06
-
-
Save bbookman/e5c6030a9e2624bbdb85e1e5e2efa37f to your computer and use it in GitHub Desktop.
Python List Comprehension: Find words with more than 4 letters
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
'''Find all of the words in a string that are less than 4 letters''' | |
sentence = 'On a summer day somner smith went simming in the sun and his red skin stung' | |
examine = sentence.split() | |
result = [word for word in examine if len(word) >=4] | |
print(result) |
# Find all the words in a string that are less than 4 letters
string = 'all the words in a string'
my_list = [word for word in string.split(' ') if len(word) < 4]
print(my_list)
"""
Find all of the words in a string that are less than 4 letters
"""
words = [i for i in string.split() if len(i) < 4]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think mine should be shorter the code?