Home > Blockchain >  How to remove the first character of a string that's in a list? [PYTHON]
How to remove the first character of a string that's in a list? [PYTHON]

Time:07-31

I would like to remove the ["flow", "flappy", "flirtify"] first character from every single index in this array, but I don't know how. I tried almost everything but it still doesn't work. Any suggestions?

CodePudding user response:

first_char_removed = [word[1:] for word in original_list]

In the future, I would recommend posting your code attempts

CodePudding user response:

to remove the first character of a string you can just use string[1:] who return you the same string without the first character.

see code example below :


for myword in myWordsArray:
  print(myword[1:])

CodePudding user response:

[word[1:] for word in ["flow", "flappy", "flirtify"]]

you can see how to do it for a single string, and then use list comprehension

CodePudding user response:

The simplest way would probably be list comprehension

l = [e[1:] for e in ["flow", "flappy", "flirtify"]]
  • Related