Share
Walmart Labs Interview Question | Dictionary
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Write a function that takes in a list of dictionaries with a key and list of integers and returns a dictionary with the standard deviation of each list.
Note that this should be done without using the numpy built in functions.
Answer ( 1 )
def std(j):
temp=0
s,l=0,len(j)
for val in j:
s=s+val
mean=s/l
for val in j:
temp+=(val-mean)**2
temp=temp/l
return temp
def ans(p):
q={}
for i,j in p.items():
q[i]=std(j)
return q
if __name__==’__main__’:
p={1:[1,2,3,4],5:[5,9,19,10]}
l=ans(p)
print(l)