Task :With dictionary write function frekv which returns occurrence of numbers
This is my code:
def frekv(n):
b={}
for i in n:
if i in b:
b[i] +=1
else:
b[i]=1
return b
x = map(frekv,[5, 2, 4, 4, 3, 1, 3, 8])
print (list(x))
Result: {5: 1, 2: 1, 4: 2, 3: 2, 8: 1, 1: 1}
This is not a right way to return it, is there any way I could return that whole list.
return bneeds to be indented.bis a dictionary, not a list.map()? The function expects the argument to be a list, but you're calling it separately with each element of the list.