Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Function that adds a number if greater than 5 and deletes the last number added
- def push_or_pop(data):
- new_data = []
- for num in data:
- if num > 5:
- new_data.append(num)
- elif num <= 5:
- new_data.pop()
- return new_data
- #Testing the function
- print(push_or_pop([10]))
- print(push_or_pop([10, 4]))
- print(push_or_pop([10, 20, 30]))
- print(push_or_pop([10, 20, 2, 30]))
Add Comment
Please, Sign In to add comment