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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:19:03+00:00 2026-06-05T05:19:03+00:00

matrix is a list of lists with the same length. I’ve to return a

  • 0

matrix

is a list of lists with the same length. I’ve to return a dictionary of the form

{i:(l1[i],l2[i],...,lm[i])}

Where the key i is matched with a tuple the i’th elements
from each list.
Say

matrix=[[1,2,3,4],[9,8,7,6],[4,8,2,6]]

so the line:

>>> dict([(i,tuple(matrix[k][i] for k in xrange(len(matrix)))) for i in xrange(len(matrix[0]))])

does the job pretty well and outputs:

{0: (1, 9, 4), 1: (2, 8, 8), 2: (3, 7, 2), 3: (4, 6, 6)}

but fails if the matrix is empty: matrix=[]. The output should be: {}

How can i deal with this?

  • 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-05T05:19:05+00:00Added an answer on June 5, 2026 at 5:19 am

    How about this instead:

    >>> matrix = [[1,2,3,4],[9,8,7,6],[4,8,2,6]]
    >>> dict(enumerate(zip(*matrix)))
    {0: (1, 5, 4), 3: (4, 8, 6), 2: (3, 7, 2), 1: (2, 6, 8)}    
    >>> matrix = []
    >>> dict(enumerate(zip(*matrix)))
    {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a list of lists to store a matrix in python. I tried
I have a list containing objects of type numpy.ndarray, all list elements has same
I have a problem with lists/arrays/matrix at Python. I have a list of matrix
Suppose I have two lists, and corresponding elements of the lists are the same
I have a list-of-list-of-lists, where the first two act as a matrix, where I
I implemented a sparse matrix as List<Map<Integer,Double>> . To get all entries of row
I have a list of matrices, the first matrix of which looks as follows:
Given: square matrix, and list which represents the index of rows to be removed,
I have two arrays containing the same elements, but in different orders, and I
Matrix... tablix.... list/matrix... list/tablix... I have no idea. none of them do what I

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.