I have a list that looks like this ["first letter", " second letter", " third letter"]In some cases, the first character is an empty character " ". In these cases, I want to strip off the first character and modify my list to become like this:
["first letter", "second letter", "third letter"]
How can I achieve this? This doesnt work because I am not modifying the string itself and there can be more than 1 " " characters in each string. I only want to remove the first.
for i in setOfCoordinates:
if i[0] == ' ':
print('space found')
i.replace(" ", "")
I don't want to remove all spaces, just the first one
for i in setOfCoordinates:. You are already iterating over the elements of the list. Fetchingi[0]will fetch the first character of the element. Replacei[0]withitest = [i.lstrip() for i in setOfCoordinates]removes all spaces also. :)