I need to ignore the last element of a list while using for
, without creating any other list or modifying the main list on the process.
And without ignoring the last element if it was repeated in any other position that not the last. So, to ignore only its position.
Here I'm ignoring it, but I had to create 1 extra list:
list1 = [3,2,3] list1_without_last = list1
list1_without_last.remove(list1_without_last[len(list1_without_last)-1])
for i in list1_without_last :
#do something
I need something like this:
list1 = [3,2,3] for i in list1 except_list1_last_element:
Ex1 : list3 =[4,5,4,5] Output : [4,5,4]
Ex2 : list4 =[1,2,3,4] Output : [1,2,3]