Skip to content

Instantly share code, notes, and snippets.

@bbookman
Created December 26, 2018 21:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbookman/1a98da47a1a6d1ceffdd3bae7be36abe to your computer and use it in GitHub Desktop.
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
'''
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)
@SariCohen2
Copy link

You could also do it this way:
lst_include3=list(filter(lambda x: '3' in str(x), range(1,1000)))
print(lst_include3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment