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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:02:51+00:00 2026-06-13T01:02:51+00:00

SO busy with some code, and have a function which basically takes dictionary where

  • 0

SO busy with some code, and have a function which basically takes dictionary where each value is a list, and returns the key with the largest list.

I wrote the following:

def max_list(dic):
    if dic:
        l1 = dic.values()
        l1 = map(len, l1)
        l2 = dic.keys()
        return l2[l1.index(max(l1))]
    else:
        return None

Someone else wrote the following:

def max_list(dic):
    result = None
    maxValue = 0
    for key in dic.keys():
        if len(dic[key]) >= maxValue:
            result = key
            maxValue = len(dic[key])
    return result

Which would be the ‘correct’ way to do this, if there is one. I hope this is not regarded as community wiki (even though the code works), trying to figure which would be the best pattern in terms of the problem.

  • 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-13T01:02:52+00:00Added an answer on June 13, 2026 at 1:02 am

    the most pythonic would be max(dic,key=lambda x:len(dic[x])) … at least I would think …

    maximizing readability and minimizing lines of code is pythonic … usually

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have code similar to this for a form: $('#some-form') .submit(function() { //
i have some code like below, i am trying to connect a server which
I am looking over some code to review and have come across a busy
I am busy writing my own collection type and need to have a function
I have some code that looks like: class Parent { private Intermediate intermediateContainer; public
We have rather large code base (150+ projects, 400000+ lines of Java code, some
assume you have a function that polls some kind of queue and blocks for
I have an FLA done in Flash 10, and some AS3 code that manipulates
The key to this question is aiding unit-testing. If I have a busy __init__
I'm busy on a project and I have some extra javascript files that need

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.