Created
September 22, 2017 16:31
-
-
Save udhayprakash/8c2c3a7a3057c7ec50f25c1fbd3f295f to your computer and use it in GitHub Desktop.
dictionary_reformatting.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""" | |
Input : | |
{'fruits':{'a':'no','b':'no',c:'yes'},'vegetables':{'x':'no','y':'yes'}} | |
Output: | |
[{'fruits':{c:'yes'},'vegetables':{'y':'yes'}}] | |
(if value contain "no" then remove that pairs) | |
""" | |
myDict = {'fruits':{'a':'no','b':'no','c':'yes'},'vegetables':{'x':'no','y':'yes'}} | |
print(myDict) | |
newDict = {} | |
for key,valueDict in myDict.items(): | |
#print key,valueDict | |
temp = {} | |
for d in valueDict: | |
if valueDict[d] != 'no': | |
temp[d] = valueDict[d] | |
newDict[key] = temp | |
print(newDict) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment