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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:52:13+00:00 2026-06-09T18:52:13+00:00

I have lists inside a dictionary: Number_of_lists=3 #user sets this value, can be any

  • 0

I have lists inside a dictionary:

Number_of_lists=3           #user sets this value, can be any positive integer
My_list={}
for j in range(1,Number_of_lists+1):
  My_list[j]=[(x,y,z)]  

The Number_of_lists is a variable set by the user. Without knowing beforehand the value set by the user, i would like to finally have a merged list of all dictionary lists. For example if Number_of_lists=3 and the corresponding lists are My_list[1]=[(1,2,3)] , My_list[2]=[(4,5,6)] , My_list[3]=[(7,8,9)] the result would be:

All_my_lists=My_list[1]+My_list[2]+My_list[3]

where:
All_my_lists=[(1,2,3),(4,5,6),(7,8,9)].

So what i’m trying to do is automate the above procedure for all possible:

Number_of_lists=n #where n can be any positive integer

I’m a bit lost up to now trying to use an iterator to add the lists up and always fail. I’m a python beginner and this is a hobby of mine, so if you answer please explain everything in your answer i’m doing this to learn, i’m not asking from you to do my homework 🙂

EDIT

@codebox (look at the comments below) correctly pointed out that My_List as displayed in my code is in fact a dictionary and not a list. Be careful if you use any of the code.

  • 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-09T18:52:14+00:00Added an answer on June 9, 2026 at 6:52 pm

    use a list comprehension:

    >>> Number_of_lists=3 
    >>> My_list={}
    >>> for j in range(1,Number_of_lists+1):
          My_list[j]=(j,j,j)
    >>> All_my_lists=[My_list[x] for x in My_list]
    
    >>> print(All_my_lists)
    [(1, 1, 1), (2, 2, 2), (3, 3, 3)]
    

    All_my_lists=[My_list[x] for x in My_list] is equivalent to:

    All_my_lists=[]
    for key in My_list:
       All_my_lists.append(My_list[key])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a dictionary containing 2 or more lists, how can I quickly
I have a dictionary with this signature: Dictionary<decimal, int> Items inside it look like
I have a list of <p> inside a <div id=someDiv> I use this code
I have a dictionary declared like this. public static Dictionary<int?, List<int?>> pegMap = new
I have lists inside a div called header which I want to expand the
I have a list of Persons inside a Company Class. public class Company{ IList<Person>
I have a list of images inside divs and a jquery ui slider, when
I have a navigation list I placed inside of a , I am attempting
I have a list item with a button inside. When the button is shown,
I have a list which have divs inside it.. Now when i use nested

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.