Issue
I have a dictionary (created by plistlib) that has some values which are displayed enclosed in {}. How do I detect these values and iterate through them?
Solution
Values displayed enclosed in {}
like {a: b, c: d}
are called dictionaries. Values like {a, b, c}
are called sets. In your case, they are dictionaries.
dictionary = {'a': {'b', 'c'}, 'd': 1}
for key, value in dictionary.iteritems():
if isinstance(value, dict): # Check if value is dictionary
print value, "is a dictionary"
else:
print value, "is not a dictionary"
Answered By - Franz Wexler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.