Slice every string in list in Python

前端 未结 3 1417
别那么骄傲
别那么骄傲 2020-12-22 03:38

I want to slice every string in a list in Python.

This is my current list:

[\'One\', \'Two\', \'Three\', \'Four\', \'Five\']

This i

3条回答
  •  执念已碎
    2020-12-22 04:20

    You can do:

    >>> l = ['One', 'Two', 'Three', 'Four', 'Five'] 
    >>> [i[:-2] for i in l]
    ['O', 'T', 'Thr', 'Fo', 'Fi']
    

提交回复
热议问题