想用对应的 ASCII 替换单词中的所有法语字母。
letters = [['é', 'à'], ['è', 'ù'], ['â', 'ê'], ['î', 'ô'], ['û', 'ç']]
for x in letters:
for a in x:
a = a.replace('é', 'e')
a = a.replace('à', 'a')
a = a.replace('è', 'e')
a = a.replace('ù', 'u')
a = a.replace('â', 'a')
a = a.replace('ê', 'e')
a = a.replace('î', 'i')
a = a.replace('ô', 'o')
a = a.replace('û', 'u')
a = a.replace('ç', 'c')
print letters[0][0]
此代码打印
é
然而。我怎样才能使这项工作?
最佳答案
我建议您考虑使用 translation tables .
translationTable = str.maketrans("éàèùâêîôûç", "eaeuaeiouc")
test = "Héllô Càèùverâêt Jîôûç"
test = test.translate(translationTable)
print(test)
将打印
Hello Caeuveraet Jiouc
.抱歉我法语不好。
关于Python:用英语替换法语字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41004941/