Home > Software design >  .count vs .count() in python?
.count vs .count() in python?

Time:08-05

I've been going through some built in functions in python as a refresher course and wanted to get some input on this snip of code that counts the majority number of occurrences in a list.

def function(Array):
   return max(set(Array), key = Array.count) 

# wondering what .count vs .count() does in this situation

CodePudding user response:

Array.count will set key to the function that this refers to while Array.count() will run the function and set key to the return of the function

  • Related