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

31st Jan 2017, 3:20 PM
Guido Parlatore
Guido Parlatore - avatar
2 Respostas
+ 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]
31st Jan 2017, 3:30 PM
Makhloufi Hocine
Makhloufi Hocine - avatar
0
# you can also use slicing my_list = ['one','two','three','four','five'] my_short_list = my_list[:-1] print(my_short_list)
31st Jan 2017, 7:35 PM
richard