2
我有一个德语单词列表,我想消除所有名词,因此我会照顾第一个字母是大写还是小写。除了以变音符号开头的单词之外,这适用于所有单词。 "Äpfel"
。在Python中比较德语变音词
# -*- coding: utf-8 -*-
dictionary = open('dictionary/de.dict', 'r')
for line in dictionary:
if line[0] == "Ä": # This does not work
print "Ä found"
我该如何做这项工作?
哪个版本的Python? – 2014-11-23 15:17:09
@tristan Python 2.7 – displayname 2014-11-23 15:18:04
问题不是“Ä”,它是行[0]。这只是一行的第一个字节,但“Ä”是一个双字节的Unicode字符。你可以通过'print line [0:3]'来检查它,它给出'Äp'而不是'Äpf'。您也必须将输入视为unicode。见但以理的回答。 – sweber 2014-11-23 15:29:29