How to delete the very last character from every string in a list of strings

后端 未结 4 642
长发绾君心
长发绾君心 2021-01-11 12:55

I have the strings \'80010\', \'80030\', \'80050\' in a list, as in

test = [\'80010\',\'80030\',\'80050\']

How can I delete the very last

4条回答
  •  感动是毒
    2021-01-11 13:20

    Just to show a slightly different solution than comprehension, Given that other answers already explained slicing, I just go through at the method.

    With the map function.

    test = ['80010','80030','80050']
    print map(lambda x: x[:-1],test)
    # ['8001', '8003', '8005']
    

    For more information about this solution, please read the brief explanation I did in another similar question.

    Convert a list into a sequence of string triples

提交回复
热议问题