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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:11:51+00:00 2026-06-02T07:11:51+00:00

I have a variable number of lists and I wanted to find the maximum

  • 0

I have a variable number of lists and I wanted to find the maximum of each of these numbers from all the lists.

I’m trying to use the map function to map the maximum of all the lists and I need to use the generator expression to pass the parameters in the map function.

I’m using something like this but it does not work:

map(max,x[c] for c in x.keys())

As an example my lists are in a dictionary:

{1: [0, 1, 0, 0, 3, 0],
 2: [1, 0, 0, 0, 0, 4, 5],
 3: [0, 5, 6, 0, 1, 1]}

You probably noticed that the lists are not all of equal sizes and that’s how I want them to be because of the way I have the data that I need to parse.

The result of this should be: [1, 5, 6, 0, 3, 4, 5]

Please do suggest if there are other ways to doing this.

Above is an example of the list. I cannot use x.values() to retrieve the lists because of the way my actual dictionary is set up. Lists are embedded at the bottom of hierarchy and I need to iterate over the top of hierarchy to retrieve the lists to compare. I must use a generator expression to retrieve all the lists so please provide solutions without the use of x.values()

  • 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-02T07:11:52+00:00Added an answer on June 2, 2026 at 7:11 am

    To get the maxs past the end of the shortest value, you need izip_longest:

    from itertools import izip_longest
    
    d={1: [0, 1, 0, 0, 3, 0],
     2: [1, 0, 0, 0, 0, 4, 5],
     3: [0, 5, 6, 0, 1, 1]}
    
    # there are other variations like
    # [max(column) for column in izip_longest(*d.itervalues())]
    print map(max, izip_longest(*d.values()))
    # [1, 5, 6, 0, 3, 4, 5]
    

    It’s known as zip_longest on Python 3.


    This is still the way to do it even if you don’t have a simple method to access all of the lists. You can get the lists however you want:

    d = {1: {'a': [0, 1, 0, 0, 3, 0]},
         2: {'a': [1, 0, 0, 0, 0, 4, 5]},
         3: {'a': [0, 5, 6, 0, 1, 1]}}
    
    def value_gen(obj):
        for key in obj:
            yield obj[key]['a']
    

    Then use:

    map(max, izip_longest(*value_gen(d)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Python I have a list of n lists, each with a variable number
I have a query and a loop written that lists all the rows from
How I can have variable number of parameters in my function in C++. Analog
I have a variable number of points on a canvas. Sometime its four other
I have strings that contain a variable number of leading hyphens and which may
I have a PHP function that takes a variable number of arguments (using func_num_args()
I have an app that creates a variable number of ScatterviewItems based on which
I have a function that accepts a variable number of parameters: foo (Class... types);
I have a datagrid with a variable number of columns that I am generating
If I have a variable with the number associated with a gridview position (id

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.