简体   繁体   中英

Remove a character in string and the 3 characters after that, python

Remove all '#' and the three characters after a '#', a '#' after the first '#' is treated as a regular character.

I tried to do it as a list but forgot that strings do not work the same as lists.

for i in phrase:
 if '#' in i:

You can do this with the simple string.split method built into python.

Example:

for i in phrase.split():
  if i == '#':
    # do whatever

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM