I want to slice every string in a list in Python.
This is my current list:
[\'One\', \'Two\', \'Three\', \'Four\', \'Five\']
This i
Use a list comprehension to create a new list with the result of an expression applied to each element in the inputlist; here the [:-2] slices of the last two characters, returning the remainder:
[w[:-2] for w in list_of_words]
Demo:
>>> list_of_words = ['One', 'Two', 'Three', 'Four', 'Five']
>>> [w[:-2] for w in list_of_words]
['O', 'T', 'Thr', 'Fo', 'Fi']