I have a function called pop_item() that I am trying to make act like a pop() that works with the list class, how would I do that, here is my code: def empty(lst): return lst == []
def pop_item(lst):
lst = lst[::-1]
new_lst = []
for i in lst:
if i != lst[-1]:
new_lst += [i]
lst = new_lst
return lst
def main():
todo = [1,2,3,4]
print(todo) #prints [1,2,3,4] as expected
print('\n' + 75 * '_' + '\n')
print(pop_item(todo)) #pop the item off
print(todo) #output should then be [1,2,3]
if __name__ == '__main__':
main()
Note: I am not allowed to use any built in functions eg len(),index,del() etc.