How should we get the key of the highest value in python dictionary without using a inbuilt functions
{1: 1, 2: 1, 3: 1, 4: 3, 5: 2} **Expecting answer to be 4**
This can be easily done by
max_key = max(check, key=lambda k: check[k])
But wanted to try without builtin function(without max, lambda)
Any help is much appreciated
my full code
def array(num):
check={}
for i in range(len(num)):
if num[i] in check:
check[num[i]]+=1
else:check[num[i]]=1
max_key = max(check, key=lambda k: check[k])
array([1,2,3,4,5,4,5,4])