python - Extracting Values in setdefault set dictionary -
i setting dictionary using setdefault option
self.dict = {} self.dict.setdefault(key, {})
i saving multiple values against key. after saving values dictionary contains:
self.dict = {'key1': {2: 1} , 'key2' : {3:4} }
how can extract multiple values of key in case mentioned below:
if key1 in self.dict:
value2 = ? (extract value 2 in {2: 1}) value1 = ? (extract value 1 in {2: 1})
dict.items()
list of pairs dict contains.
to first pair, do:
dct = self.dict['key1'] value1, value2 = dct.items()[0]
python python-2.7 dictionary
No comments:
Post a Comment