Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. print ("Bismillah ArRahmanir Rahim")
  2. print ("\nSelected elements from a list.")
  3.  
  4.  
  5. new_list = list()
  6. a = [1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 14, 32, 23, 34, 45]
  7.  
  8. for element in a:
  9. if element < 5:
  10. new_list.append(element)
  11. print (new_list)
  12. #code in one line (extra)
  13. print ("Extra")
  14. print ([aa for aa in a if aa < 5])
  15. number_list = [1, 1, 2, 3, 4, 5, 8, 13, 21, 34, 55, 89]
  16. print ([number for number in number_list if number < 5])
  17.  
  18. num = input ("Enter a number: ")
  19. print ("The numbers in the list that are less than", num)
  20. for element in a:
  21. if element < int (num):
  22. new_list.append(element)
  23. print (new_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement