Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 1
Please help me out š„ŗ
Š½Š° Š²Ń Š¾Š“ Ń ŠæŠ¾Š»ŃŃŠ°Ń ŃŠæŠøŃŠ¾Šŗ, Š½Š° Š²ŃŃ Š¾Š“Šµ Š¼Š½Šµ Š½ŃŠ¶Š½Š¾ ŠæŠ¾Š»ŃŃŠøŃŃ ŃŃŠ¾Ń ŃŠæŠøŃŠ¾Šŗ Š±ŠµŠ· Š±ŃŠŗŠ² Ń Šø Š at the input I get a list, at the output I need to get this list without the letters Ń and Š https://code.sololearn.com/cijkbH1K5iX1/?ref=app
8 Respostas
+ 2
x=['ŠŠ¶', 'Š·ŠµŠ»ŃŠ½ŃŠ¹', 'ŠŠ', 'Š³ŠŠ¢Š¬ŃŃŠ®ŃŃŠ·ŠŖŠŠŠ']
def replacer(x):
s=[]
for i in x:
if 'Ń' in i and 'Š'in i:
m=i.replace('Ń','Šµ')
m =m.replace('Š','Š') #edit use m, not i
elif 'Š'in i:
m=i.replace('Š','Š')
elif 'Ń' in i:
m=i.replace('Ń','Šµ')
s.append(m)
return s
#x=input().split(', ')
print(replacer(x))
+ 6
murrr ,
to replace various characters, we can use 2 very nice string methods in python:
> str.maketrans(...) defines character pairs in a dict. these pairs are converted to unicode id's
> str.translate(...) is used to take a dict (created by maketrans()), and applies the replacement to a string
you can find a sample how it works in the attached file:
https://code.sololearn.com/cweDcS7bHqO6/?ref=app
+ 2
I updated code.
use, need to use updated m in place of I in first if..
m=i.replace('Ń','Šµ').replace('Š','Š')
+ 2
I just gave working code but actually there you don't need to check condition.. This codes works same as your original.
x=['ŠŠ¶', 'Š·ŠµŠ»ŃŠ½ŃŠ¹', 'ŠŠ', 'Š³ŠŠ¢Š¬ŃŃŠ®ŃŃŠ·ŠŖŠŠŠ']
s = []
for i in x :
m = i.replace('Ń','Šµ').replace('Š','Š')
s.append(m)
print(s)
#or simply , can be in one line.
s = [ i.replace('Ń','Šµ').replace('Š','Š') for i in x ]
print(s)
+ 1
But it still prints Ń in words where both Ń and Ć meet
+ 1
It works THANKS A LOT !!!!
+ 1
Wow, thanks
+ 1
Thanks š