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 353885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:52:20+00:00 2026-05-12T11:52:20+00:00

I have a dictionary dict1[‘a’] = [ [1,2], [3,4] ] and need to generate

  • 0

I have a dictionary dict1['a'] = [ [1,2], [3,4] ] and need to generate a list out of it as l1 = [2, 4]. That is, a list out of the second element of each inner list. It can be a separate list or even the dictionary can be modified as dict1['a'] = [2,4].

  • 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-05-12T11:52:20+00:00Added an answer on May 12, 2026 at 11:52 am

    Assuming that each value in the dictionary is a list of pairs, then this should do it for you:

    [pair[1] for pairlist in dict1.values() for pair in pairlist]
    

    As you can see:

    • dict1.values() gets you just the values in your dict,
    • for pairlist in dict1.values() gets you all the lists of pairs,
    • for pair in pairlist gets you all the pairs in each of those lists,
    • and pair[1] gets you the second value in each pair.

    Try it out. The Python shell is your friend!…

    >>> dict1 = {}
    >>> dict1['a'] = [[1,2], [3,4]]
    >>> dict1['b'] = [[5, 6], [42, 69], [220, 284]]
    >>> 
    >>> dict1.values()
    [[[1, 2], [3, 4]], [[5, 6], [42, 69], [220, 284]]]
    >>> 
    >>> [pairlist for pairlist in dict1.values()]
    [[[1, 2], [3, 4]], [[5, 6], [42, 69], [220, 284]]]
    >>> # No real difference here, but we can refer to each list now.
    >>> 
    >>> [pair for pairlist in dict1.values() for pair in pairlist]
    [[1, 2], [3, 4], [5, 6], [42, 69], [220, 284]]
    >>> 
    >>> # Finally...
    >>> [pair[1] for pairlist in dict1.values() for pair in pairlist]
    [2, 4, 6, 69, 284]
    

    While I’m at it, I’ll just say: ipython loves you!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dictionary/list balance_sign_dict from which I need to retrieve 2 values based
Have Dictionary <Int64, byte> that gets used a lot. I mean in a loop
I have a dictionary in Python, that describes some kinds of binaries running on
For this example, I have a dictionary, that when I call on it, Ember
I have dictionary that is built as part of the initialization of my object.
I have a dictionary >>>d = {a:apple, c:cat, d:dog} That dictionary should be printed
Really two questions: If I have a dictionary (that originally came from parsing a
Say I have a dictionary dict, with the following values: dict1 = {'1': ['a','b',
If I have a data tree that is something like : NSMutableDictionary (dict1) NSMutableDictionary
I have a dictionary and a list. The values of the keys match those

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.