Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This push_or_pop function accepts a list of numbers
- # returns a new list by iterating over the list of numbers
- # if a number is greater than 5, it adds it to the end of the new list
- # if a number is less than or equal to 5, it removes the last element added to it.
- """ I noticed for the example given in the coding challenge 12 that line 8 should have
- given a list of [10] and not an empty list.
- so also line 10, it should have given a list of [10, 20, 30]
- so if my analysis of this challenge is right, I will try to code this challenge to what
- I think should be correct.
- """
- def push_or_pop(anylist):
- new_list = []
- new_list1 = []
- for number in anylist:
- if number > 5:
- new_list.append(number)
- return new_list
- print(push_or_pop([6, 2, 8, 1, 9]))
- print(push_or_pop([21, 4, 8]))
- print(push_or_pop([2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement