Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. # This push_or_pop function accepts a list of numbers
  2. # returns a new list by iterating over the list of numbers
  3. # if a number is greater than 5, it adds it to the end of the new list
  4. # if a number is less than or equal to 5, it removes the last element added to it.
  5.  
  6. """ I noticed for the example given in the coding challenge 12 that line 8 should have
  7.    given a list of [10] and not an empty list.
  8.    so also line 10, it should have given a list of [10, 20, 30]
  9.    
  10.    so if my analysis of this challenge is right, I will try to code this challenge to what
  11.    I think should be correct.
  12. """    
  13.  
  14. def push_or_pop(anylist):
  15.    
  16.     new_list = []
  17.     new_list1 = []
  18.     for number in anylist:
  19.         if number > 5:
  20.             new_list.append(number)
  21.        
  22.        
  23.        
  24.     return new_list
  25.    
  26. print(push_or_pop([6, 2, 8, 1, 9]))
  27. print(push_or_pop([21, 4, 8]))
  28. print(push_or_pop([2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement