这里有点奇怪。我有一个相邻列表,键中有umlauts。但列表中的编码似乎有所不同,当我遍历它时:
adjacency_list = {
'root': ['zuw\xc3\xa4chse', 'test2'],
'zuw\xc3\xa4chse': ['test3', 'test4']
}
print(adjacency_list['root'])
for child in adjacency_list['root']: print(child)
输出:
['zuw\xc3\xa4chse', 'test2']
zuwächse
test2
为什么列表中有'zuw\xc3\xa4chse',但如果我有for child in...
child现在是'zuwächse'?为什么编码会不同?我需要相同的编码,这样我就可以使用child
的值作为键
编辑
多亏了Padraic Cunningham:如果你打印一些东西,它就会通过repr。这意味着键没有改变,只是它的视觉表现。结果发现这与我遇到的实际问题无关,而且完全是红色的
目前没有回答
相关问题 更多 >
编程相关推荐