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

  • Home
  • SEARCH
  • 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 7009085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:49:03+00:00 2026-05-27T21:49:03+00:00

I have a list M below which came from an external file (This is

  • 0

I have a list M below which came from an external file (This is a large list in reality, len(M)>10000).

M=[(1, 100), (2, 200), (3, 300), (4, 400)]

However, I want to separate it into M1=[1,2,3,4] and M2=[100,200,300,400].
Here is how I do it at the moment,

M1 = [] 
M2 = [] 
for M1,M2 in M:
  M1.append(M1) 
  M2.append(M2)

I was wondering if there is a simpler and more efficient way to do it, a solution that uses built-in functions in Python.

  • 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-27T21:49:04+00:00Added an answer on May 27, 2026 at 9:49 pm

    Just do it:

    M1, M2 = zip(*M)
    

    M1 and M2 will be tuples. You can transform them into lists if you want:

    M1, M2 = map(list, zip(*M))
    

    or with a genexp:

    M1, M2 = (list(i) for i in zip(*M))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file list as given below which is used by an existing
I have a list of items (blue nodes below) which are categorized by the
I have the below code, which iterates over a list based on a custom
I have below a list of text, it is from a popular online game
I have the following unorderered list code which displays the list below: <ul> <li
I have a list which is shown below. plist = [('s', [0.0, 0.1, 0.0,
I recently came across the link below which I have found quite interesting. http://en.wikipedia.org/wiki/XOR_linked_list
I have a list (see below) contained in a window. The window's DataContext has
I have a List of HashMap such as below ArrayList l = new ArrayList
I have a list of points as shown below points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]

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.