def apriori_gen(f_items):
    """
    Create (k+1)-itemsets from all frequent k-itemsets.

    Those are candidates for frequent (k+1) itemsets. This step is known as
    'candidate generation'.
    """
    new_f_items = []
    for i, itemset1 in enumerate(f_items):
        for itemset2 in f_items[i+1:]:
            # Check if those sets, which are guaranteed to have the same
            # number of elements, differ only by 1 element.
            if len(itemset1['itemset'] - itemset2['itemset']) == 1:
                new_f_items.append({'itemset': (itemset1['itemset']
                                                .union(itemset2['itemset']))})
    return new_f_items