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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:26:58+00:00 2026-06-14T20:26:58+00:00

I understand a = max(set(lst), key=lst.count) will derive most common element in a list

  • 0

I understand

a = max(set(lst), key=lst.count)

will derive most common element in a list

but how do you derive most common element in a list of list without using helper function?

For example

lst = [['1','2','3','4'],['1','1','1','1'],['1','2','3','4']]

The output should equal 1.

When I try a = max(set(lst), key=lst.count)

it writes builtins.TypeError: unhashable type: 'list'

Can anyone please help me?

  • 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-14T20:26:59+00:00Added an answer on June 14, 2026 at 8:26 pm

    There are many ways, but I wanted to let you know that there are some nice tools for that kind of things in the standard modules, e.g. collections.Counter:

    In [1]: lst = [['1','2','3','4'],['1','1','1','1'],['1','2','3','4']]
    In [2]: from collections import Counter
    In [3]: from operator import itemgetter
    In [4]: max((Counter(l).most_common(1)[0] for l in lst), key=itemgetter(1))[0]
    Out[4]: '1'
    

    Or, you could (kinda) employ your current solution for each of the sublists:

    In [5]: max(((max(set(l), key=l.count), l) for l in lst),
       ...: key=lambda x: x[1].count(x[0]))[0]
    Out[5]: '1'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand this axis scaling. I'm able to set the max/min by changing
Im recieving an error that I dont understand using FCM. If I set options
I understand, from MSDN, that ClassInitialize is to mark a method that will do
I understand this is an easy question but for some reason this just isn't
I understand what weak tables are. But I'd like to know where weak tables
Let say I got the following : DECLARE @ExcludedList VARCHAR(MAX) SET @ExcludedList = 3
I have a system set up currently that is using celery with a redis
I am new to MS ADO and trying to understand how to set the
I've been looking for a way to center a div with a set max-width.
I'm using Symfony 2 with doctrine. I've set up a custom repository with a

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.