def get_index(x):
    for i, e in enumerate(sort_map):
        if x['key'].startswith(e):
            return i
buckets = sorted(buckets, key=get_index)
Python 3 sort list of dictionaries by value, where values begin with string