0
How can i remove the last word from a list?(python)
the list is made by an imput so the number of words in the list can change
2 odpowiedzi
+ 2
list1 = ["one", "two" , "three", "four", "five"]
list1.remove(list1[-1])
print (list1)
list2 = [10, 3, 4, 44, 8]
list2.remove(list2[-1])
print (list2)
result:
['one', 'two', 'three', 'four']
[10, 3, 4, 44]
0
# you can also use slicing
my_list = ['one','two','three','four','five']
my_short_list = my_list[:-1]
print(my_short_list)