Q: Replacing a character in a elements of string list I have a list in which some strings end with a certain character .Now I need to remove this character from  these strings. 
say : ['abc-','xyz','jkl-']
result should be ['abc','xyz','jkl']
What I am trying is: 
>>>List.append([s.replace('- ',' ')[:-1] for s in List ])

But it removes the last character from other strings as well .

A: You are trying to match to replace with '- ', your character followed by a whitespace character. There are no whitespaces in your strings, hence replace does nothing and then you just slice all of your strings' last character off. Furthermore, there is no point in adding a space and then slicing it off, and your current method wouldn't account for your character elsewhere in your string, for instance two-putt. 
Just remove the slice and use rstrip to remove the trailing character you don't want. 
>>> l=['abc-','xyz','jkl-']
>>> l[:]= [x.rstrip('-') for x in orig]
['abc', 'xyz', 'jkl']

You can use a list comprehension to create a new list then just overwrite your original's contents. Note that with this method, if your strings end with several of the character you don't want, they will all be removed, for example. 'dogs---' will become 'dogs'. If you want to handle trailing whitespace as well, you can supplement a space along with the character you do not want to rstrip, with .rstrip('- ').

A: You can use a list comprehension which considers every item in your list and for each item, takes all but the last character if the last character is a dash:
>>> List = ['abc-', 'xyz', 'jlk-']
>>> [x[:-1] if x.endswith('-') else x for x in List]
['abc', 'xyz', 'jlk']

