Walmart Labs Interview Question | Dictionary

Question

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.

in progress 1
Dhruv2301 55 years 1 Answer 1165 views Great Grand Master 0

Answer ( 1 )

  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)

Leave an answer

Browse
Browse