【发布时间】:2016-03-23 15:31:35
【问题描述】:
我通过在 python 中执行 .append 添加到字典
theDict = defaultdict(list)
theDict[theKey].append(theValue)
我会尝试通过以下方式打印出来
print theDict[valueKeyToLookUp]
但它总是看起来像这样:
[u'STRING_I_WANT']
我尝试在前面使用 str() 进行打印,但它仍然将 u' 留在那里。
我试过这个:Python string prints as [u'String'] 这样做
valueKeyToLookUp.encode('ascii')
但结果还是一样。其他解决方案看起来像是通过数字在列表中的位置来查找值,但我需要按值进行。
有什么想法吗?
【问题讨论】:
-
以下问题可能会有所帮助stackoverflow.com/questions/19527279/…
标签: python dictionary unicode