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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T19:30:36+00:00 2026-06-18T19:30:36+00:00

I have an array of array in python. What is the best way to

  • 0

I have an array of array in python. What is the best way to convert it to an array in python?
for example:

m = [[1,2],[3,4]]
# convert to [1,2,3,4]

I am new in python, so I dont know any solution of it better than writing a loop. Please help.

  • 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-18T19:30:37+00:00Added an answer on June 18, 2026 at 7:30 pm

    Use itertools.chain or list comprehension:

    from itertools import chain
    
    list(chain(*m))  # shortest
    # or:
    list(chain.from_iterable(m)) # more efficient  
    

    For smaller lists comprehension is faster, for longer ones chain.from_iterable is more suitable.

    [item for subl in m for item in subl]
    

    For understanding the nested comprehension, you can split it across multiple lines and compare it to a regular for loop:

    [item                         #result = []
        for subl in m             #for subl in m:  
            for item in subl]     #    for item in subl:
                                  #        result.append(item)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am new to python and have a question about the best/pythonic way
I'm very new to python. I would like to have an array of exactly
In Python, is there a better way to parameterise strings into regular expressions than
I have the following array(in python): arr= ['\n', ' a#B\n', ' c#D\n'] Now I
I have a 3D array in Python and I need to iterate over all
I have a char array in Python, which is read from a file e.g.
I have a problem with initialzing a 2D array in python. I want a
I am creating an object in python. I have a numpy array from an
If I have a list(or array, dictionary....) in python that could exceed the available
I have the following array in Python: points_list = [point0, point1, point2] where each

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.