鉴于此元组列表:
lists = [('the', 'DT'), ('cat', 'NN'), ('drink', 'NN'), ('the', 'DT'), ('soup', 'NN')]
在哪里,
DT NN NN DT NN
是每个单词的词性标签,我将其转换lists
为字典:
my_dict = dict(lists)
它给了我这个输出:
{'soup': 'NN', 'the': 'DT', 'drink': 'NN', 'cat': 'NN'}
我注意到只有一个'the': 'DT'
,而且顺序也发生了变化。我期望的是转换后的lists
会是这样的:
{'the': 'DT','cat': 'NN','drink': 'NN','the': 'DT','soup': 'NN'}
然后使用 pypyodbc,我将在我的数据库(sql server)中查询 in 的Tagalog
值:key
my_dict
myDatabase
+---------+---------+
| English | Tagalog |
+---------+---------+
| cat | pusa |
| soup | sopas |
| the | ang |
| drink | inom |
+---------+---------+
并将输出显示为这样的字符串:
ang pusa inom ang sopas