If you have a given list of lists what's the best way to sort them proportionally? Is there a better way to do this?The idea is that in a case of web scraping, you would want to avoid hitting google all the time and want to distribute calls so that they are as even as possible.Is this a thing that can be done more efficiently than this terribad code that I wrote?urls = [        ['http://google.com/search','redirect.com', 0],        ['http://duckduckgo.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0],        ['http://bing.com/search','redirect.com', 0],        ['http://yahoo.com/search','redirect.com', 0],        ['http://yahoo.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0],        ['http://bing.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0],        ['http://yahoo.com/search','redirect.com', 0],        ['http://altavista.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0],        ['http://yahoo.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0],        ['http://altavista.com/search','redirect.com', 0],        ['http://google.com/search','redirect.com', 0]    ]def get_domain( url ):    domain = ''    parts = tldextract.extract( url )    if parts.subdomain != '' and parts.subdomain != 'www':        domain = parts.subdomain + '.' + parts.domain + '.' + parts.suffix    else:        domain = parts.domain + '.' + parts.suffix    return domaindef proportional_sort( urls ):    doms = [get_domain(url[0]) for url in urls]    dom_set = set(doms)    matrix = {}    for domain in dom_set:        sublist = [item for item in urls if get_domain(item[0]) == domain]        # print sublist        random.shuffle(sublist)        if len(sublist) in matrix:            matrix[len(sublist)][domain] = sublist        else:            matrix[len(sublist)] = {}            matrix[len(sublist)][domain] = sublist    # print matrix.keys()    map_vector = []    for key in matrix:        map_vector += [key] * key * len(matrix[key])        map_vector = sorted(map_vector, key=int)    # print map_vector    proportionally_sorted = []    for pos in map_vector:        if pos in matrix:            rand_pos = [pos]            for key in matrix.keys():                if key % pos == 0:                    rand_pos.append(key)            for position in rand_pos:                rand_keys = matrix[position].keys()                random.shuffle(rand_keys)                for key in rand_keys:                    rand = rand_keys.pop()                    if matrix[position][rand]:                        proportionally_sorted.append(matrix[position][rand].pop())                        break                    else:                        continue    return proportionally_sorted
Proportional sorting of web scrape results
python;algorithm