+ 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 👍