If i had a list as an example:
a = ['Hello_1.txt', 'Hello_2.txt']
In Python is it possible to somehow remove the first 5 characters ('Hello'
)
and the last 3 characters ('txt'
) from each of the items in the list ?
You could use a list-comprehension and string slicing:
[s[5:-3] for s in a]
which gives what you describe (not sure this is the neatest output though!)
['_1.', '_2.']