import random


def reduce_dicts(titles, gold, shuffle=False):
    """ reduce 2 dictionaries to 2 lists,
    providing 'same index' iff 'same key in the dictionary'
    """
    titles, gold = dict(titles), dict(gold)
    titles_list = []
    gold_list = []
    for key in titles:
        titles_list.append(titles[key])
        gold_list.append(gold[key])

    if shuffle:
        # this is the only way to shuffle them
        zipped = list(zip(titles_list, gold_list))
        random.shuffle(zipped)
        titles_list, gold_list = zip(*zipped)

    return titles_list, gold_list