簡體   English   中英

從元組列表創建單詞替換字典

[英]Create a word replacement dictionary from list of tuples

我有一個元組列表,我正在嘗試制作一個單詞替換詞典。
我的清單與此類似:

word_list = [('horse','et'),('horses','ft'),('dog','et'),('dogs','ft')]

我已經設法創建一個像這樣的字典:

word_dict = { 'et': ['horse','dog'], 'ft': ['horses','dogs'] }

我不想要的是這樣的字典:

word_dict = { 'horse':'dog', 'horses':'dogs' }

我是python的新手,無法弄清楚這個問題或在這里找到答案。
如何創建此詞典?
任何幫助將不勝感激。

那這個呢:

>>> word_dict = {'et': ['horse','dog'], 'ft': ['horses','dogs']}
>>> dict(word_dict.values())
{'horses': 'dogs', 'horse': 'dog'}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM