This function take long time for big dicts. Try use kind of indexes with tempolary arrays,dicts that will limit loops... Think what are you sorting out... :)

# def sortDict(a,k):  n=len(a)  while True:   nxt = None   tmp = None   b = iter(a)   i = next(b,None)   for j in range(n):    nxt = next(b,None)    if nxt==None:     continue    if a[i][k]>a[nxt][k]:     tmp = a[i]     a[i] = a[nxt]     a[nxt] = tmp    i=nxt   if tmp==None:    break