第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在具有一個(gè)鍵的多個(gè)值的字典中添加列表或字典 - Python

在具有一個(gè)鍵的多個(gè)值的字典中添加列表或字典 - Python

素胚勾勒不出你 2021-06-04 17:31:01
第一次在此發(fā)帖,如有不對(duì)之處請(qǐng)見(jiàn)諒。我有 2 個(gè)帶有鍵和列表的字典作為值。我需要為字典中的列表元素分配一個(gè)列表,該元素在其他字典 2 中匹配。Dictionary 1{'S': ['Close Coupled', 'Wall Hung', 'Btw'], 'E':['Bifold', 'Hinge', 'Sliding', 'Pivot']}Dictionary 2{'Close Coupled': ['Close Coupled Contract', 'Close Coupled Open Back', 'Close Coupled Open Back Rimless'], 'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless'],'Btw': ['BTW Contract', 'BTW Rimless'], 'Bifold': ['700', '800', '900', '1000'], 'Hinge': ['700', '800', '900', '1000'], 'Sliding': ['700', '800', '900', '1000'], 'Pivot': ['700', '800', '900', '1000']} Result I am trying to get is.{'S': {'Close Coupled':['Close Coupled Contract', 'Close Coupled Open Back', 'Close Coupled Open Back Rimless'], 'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless'], 'Btw': ['BTW Contract', 'BTW Rimless'], 'E': 'Bifold':['700', '800', '900', '1000'], 'Hinge':['700', '800', '900', '1000'],'Sliding':['700', '800', '900', '1000'], 'Pivot':['700', '800', '900', '1000']}在他之后,我有另一本將以相同方式添加的字典。它就像一個(gè)樹(shù)結(jié)構(gòu)或嵌套,但我無(wú)法建立我的邏輯來(lái)將字典分配給第一個(gè)字典中列表的每個(gè)匹配元素。如果不清楚;請(qǐng)讓我知道我會(huì)嘗試更好地解釋它。
查看完整描述

3 回答

?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

我認(rèn)為我沒(méi)有正確理解你的問(wèn)題。但是請(qǐng)檢查此代碼,如果它不適合您的需要,請(qǐng)告訴我。


d1= {'S': ['Close Coupled', 'Wall Hung', 'Btw'], 'E':['Bifold', 'Hinge', 'Sliding', 'Pivot']}


d2= {'Close Coupled': ['Close Coupled Contract', 'Close Coupled Open Back', 'Close Coupled Open Back Rimless'], 'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless'],'Btw': ['BTW Contract', 'BTW Rimless'], 'Bifold': ['700', '800', '900', '1000'], 'Hinge': ['700', '800', '900', '1000'], 'Sliding': ['700', '800', '900', '1000'], 'Pivot': ['700', '800', '900', '1000']}


final_dict= {} # create a dictionary to store the final answer

for item in d1:

    temp= dict() # temporary dictionary

    for i in item d1[item]:

        temp[i]= d2[i]

    final_dict[item]= temp

輸出

打?。╢inal_dict)


{'E': {'Bifold': ['700', '800', '900', '1000'],

  'Hinge': ['700', '800', '900', '1000'],

  'Pivot': ['700', '800', '900', '1000'],

  'Sliding': ['700', '800', '900', '1000']},

 'S': {'Btw': ['BTW Contract', 'BTW Rimless'],

  'Close Coupled': ['Close Coupled Contract',

   'Close Coupled Open Back',

   'Close Coupled Open Back Rimless'],

  'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless']}} `


查看完整回答
反對(duì) 回復(fù) 2021-06-09
?
智慧大石

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超3個(gè)贊

您可以使用dict理解來(lái)執(zhí)行此操作:


{keys : {m : d2.get(m) for m in values} for keys, values in d1.items()}



{'S': {'Close Coupled': ['Close Coupled Contract',

   'Close Coupled Open Back',

   'Close Coupled Open Back Rimless'],

  'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless'],

  'Btw': ['BTW Contract', 'BTW Rimless']},

 'E': {'Bifold': ['700', '800', '900', '1000'],

  'Hinge': ['700', '800', '900', '1000'],

  'Sliding': ['700', '800', '900', '1000'],

  'Pivot': ['700', '800', '900', '1000']}}

數(shù)據(jù):


d1 = {'S': ['Close Coupled', 'Wall Hung', 'Btw'], 'E':['Bifold', 'Hinge', 'Sliding', 'Pivot']}

d2 = {'Close Coupled': ['Close Coupled Contract', 'Close Coupled Open Back', 'Close Coupled Open Back Rimless'], 'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless'],'Btw': ['BTW Contract', 'BTW Rimless'], 'Bifold': ['700', '800', '900', '1000'], 'Hinge': ['700', '800', '900', '1000'], 'Sliding': ['700', '800', '900', '1000'], 'Pivot': ['700', '800', '900', '1000']}


查看完整回答
反對(duì) 回復(fù) 2021-06-09
?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

一種方法是遍歷您的第一個(gè)字典并從第二個(gè)字典中獲取與同名鍵對(duì)應(yīng)的列表。例如:


d1 = {'S': ['Close Coupled', 'Wall Hung', 'Btw'], 'E':['Bifold', 'Hinge', 'Sliding', 'Pivot']}

d2 = {'Close Coupled': ['Close Coupled Contract', 'Close Coupled Open Back', 'Close Coupled Open Back Rimless'], 'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless'],'Btw': ['BTW Contract', 'BTW Rimless'], 'Bifold': ['700', '800', '900', '1000'], 'Hinge': ['700', '800', '900', '1000'], 'Sliding': ['700', '800', '900', '1000'], 'Pivot': ['700', '800', '900', '1000']}

result = dict()


for key, values in d1.items():

    result[key] = dict()

    for value in values:

        result[key][value] = d2[value]


print(result)


# OUTPUT (print does not output indented results shown here for readability only)

# {

#      'S': {

#          'Close Coupled': ['Close Coupled Contract', 'Close Coupled Open Back', 'Close Coupled Open Back Rimless'],

#          'Btw': ['BTW Contract', 'BTW Rimless'],

#          'Wall Hung': ['Wall Hung Contract', 'Wall Hung Rimless']

#          },

#      'E': {

#          'Bifold': ['700', '800', '900', '1000'],

#          'Hinge': ['700', '800', '900', '1000'],

#          'Sliding': ['700', '800', '900', '1000'],

#          'Pivot': ['700', '800', '900', '1000']

#          }

# }


查看完整回答
反對(duì) 回復(fù) 2021-06-09
  • 3 回答
  • 0 關(guān)注
  • 225 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)