-1
a = "!@$%^"
s = "sfe@v%asfr"
for i in a:
  w = s.replace(i,' ')
print(w)

My output : sfe@v%asfr

Desired output : sfe v asfr

How to get the desired output?

  • Since they're all single characters, this is really easy to do with a [regular expression](https://docs.python.org/3/library/re.html): `w = re.sub(f"[{a}]", " ", s)`. – Mark Ransom Jul 23 '21 at 18:24

1 Answers1

0

You need to assign s the replaced string. w is just being over written with every iteration.

a = "!@$%^"
s = "sfe@v%asfr"
for i in a:
  s = s.replace(i,' ')
print(s)