Skip to content

Instantly share code, notes, and snippets.

@Deep18-03
Created March 29, 2020 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deep18-03/9272e01a6a7c091b18db7ae8398437cb to your computer and use it in GitHub Desktop.
Save Deep18-03/9272e01a6a7c091b18db7ae8398437cb to your computer and use it in GitHub Desktop.
'''Algorithm:
- Create new empty list
- For loop to iterate over each element
- If element < 5:
- Append the element into new list
- Print the new list'''
a = [1, 1, 2, 3, 5, 2, 13, 21, 3 4, 55, 89]
b=[]
for i in a:
if i < 5:
b.append(i)
print(b)
#single line use : print([aa for aa in a if aa < 5]) concept name:list comprehension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment