I have the strings \'80010\', \'80030\', \'80050\' in a list, as in
test = [\'80010\',\'80030\',\'80050\']
How can I delete the very last
test = ["80010","80030","80050"]
newtest = [x[:-1] for x in test]
New test will contain the result ["8001","8003","8005"]
.
[x[:-1] for x in test]
creates a new list (using list comprehension) by looping over each item in test
and putting a modified version into newtest
. The x[:-1]
means to take everything in the string value x up to but not including the last element.