Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:24:32+00:00 2026-06-01T04:24:32+00:00

I have a dict which contains some lists and some dicts, as illustrated below.

  • 0

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'}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:24:33+00:00Added an answer on June 1, 2026 at 4:24 am

    One way is to change the lone dicts into a list containing the dict. Then all the entries can be treated the same

    >>> D = {
    ...     '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'}
    ... }
    >>> L = [v if type(v) is list else [v] for v in D.values()]
    >>> [(d["Name"], d["Address"]) for item in L for d in item ]
    [('Steve Watson', 'steve.watson@example.org'), ('Daryl Hurstbridge', 'daryl.hurstbridge@example.org'), ('Sally Hervorth', 'sally.hervorth@example.org'), ('Mike Merry', 'mike.merry@example.org'), ('Jenny Callisto', 'jenny.callisto@example.org'), ('Darius Jedburgh', 'darius.jedburgh@example.org')]
    

    Or the one liner version

    [(d["Name"], d["Address"]) for item in (v if type(v) is list else [v] for v in D.values())]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some SQLAlchemy objects which contain lists of more SQLAlchemy objects, and so
I have plist which contains a dictionary say dict and in dict I have
I have to read a dict.txt file which contains one string for line and
I have some list of dicts like this: list1 = [ dict(RL = 'rl1',
I have a default dict of dicts whose primary key is a timestamp in
I have 0 or more dict s in a list: >>> dicts = [dict(a=3,
I have two Dictionary<Person,Boolean> . dict a contains : Person A -> false Person
I have used AutoCompleteBox usercontrol. I have a dictionary of type Dictionary<int,string> which contains
I have a class which contains a number of class variables : c_dict1 ,
I have created an iPad application which contains images. I am storing these images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.