我是一名Python項目和學習語言的新手。他們正在使用python v2.7。無法理解此代碼中Python字典的不同用法
字典在代碼中以不同的方式使用,我無法理解下面代碼中究竟發生了什麼。一位蟒蛇大師能爲我揭開下面的事情嗎?看看我的評論。
key_mapping={} # is being passed into the below procedure as an argument
for key, result in cache_results.iteritems(): # loop over key value pair a normal dict
client_key = self._client_key_from_result(result, oid_hoid_map, is_trade=is_trade)
if not client_key:
continue
result_key = (# I guess this is a tupple?
int(result.osKey) if is_trade else result.portfolioID,
self._force_int(result.collateralGroupID),
self._force_int(result.bookingBU)
)
key_mapping[key]=client_key, result_key # What the? huh?
results[client_key, result_key] = dict(# What in the world?
col_amts=(col_amt_ph, col_amt),
exps=(max_exp, max_exp_yr1, sum_exp) + padded_exposures,
additional_columns=(col_alpha, col_beta, col_isFinancial, col_financial_factor,
col_pd, col_lgd, col_effective_maturity, col_k, col_ead)
)
轉讓給key_mapping
令人困惑。但是,下一行字典賦予results
列表更令人困惑。不知道那裏發生了什麼。
謝謝。那麼可以肯定地說client_key是'col_amts'而result_key是'(col_amt_ph,col_amt)'? – Doublespeed
否@Doublespeed,***合併***,這兩個鍵形成一個新鍵,可用於查找包含「col_amts,exps等」的字典。請參閱我的編輯 – Bahrom