Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def freq(l):
- result = {}
- # Prepare the dictionnary of frequencies
- for a in l:
- result[a] = result[a]+ 1 if a in result else 1
- # Get the max value -frequency- in the dict.
- m = max(result.values())
- # Find all the elements that have the max frequency m
- keys = [k for k, v in result.items() if v == m]
- tup = []
- for i in keys:
- tup.append((i, result[i]))
- return tup
- # Example:
- print(freq([1, 1, 3, 3, 3, 4, 5, 4, 5, 5]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement