I have a dict which contains some lists and some dicts, as illustrated below.
What is the most pythonic way to iterate over the dict and print out the name and address pairs for each top level dict key?
Thanks
{
'Resent-Bcc': [],
'Delivered-To': [],
'From': {'Name': 'Steve Watson', 'Address': 'steve.watson@example.org'},
'Cc': [],
'Resent-Cc': [],
'Bcc': [ {'Name': 'Daryl Hurstbridge', 'Address': 'daryl.hurstbridge@example.org'},
{'Name': 'Sally Hervorth', 'Address': 'sally.hervorth@example.org'},
{'Name': 'Mike Merry', 'Address': 'mike.merry@example.org'},
{'Name': 'Jenny Callisto', 'Address': 'jenny.callisto@example.org'}
],
'To': {'Name': 'Darius Jedburgh', 'Address': 'darius.jedburgh@example.org'}
}
One way is to change the lone dicts into a list containing the dict. Then all the entries can be treated the same
Or the one liner version