Created
December 26, 2018 21:41
-
-
Save bbookman/1a98da47a1a6d1ceffdd3bae7be36abe to your computer and use it in GitHub Desktop.
Python List Comprehension: Find all of the numbers from 1-1000 that have a 3 in them
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 numbers from 1-1000 that have a 3 in them | |
''' | |
three = [n for n in range(0,1000) if '3' in str(n)] | |
print(three) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could also do it this way:
lst_include3=list(filter(lambda x: '3' in str(x), range(1,1000)))
print(lst_include3)