from functools import reduce
class Item(object):

    def __init__(self, name, price):
        self.name = name
self.price = price

def __str__(self):
    return '{0} {1}'.format(self.name, self.price)


class Person(object):

    def __init__(self, id, name, *items):
        self.id = id
self.name = name
self.items = set(items)

def __str__(self):
    return '{0} {1}: {2}'.format(self.id, self.name, map(str, self.items))
list_people = [Person('001', 'jim', Item('pencil', 0.99)), Person('002',
    'mary', Item('book', 15.49)), Person('002', 'mary', Item('tape', 7.99)),
    Person('003', 'john', Item('pen', 3.49)), Person('003', 'john', Item(
    'stapler', 9.49)), Person('003', 'john', Item('scissors', 12.99))]

def take_items(person, other):
    """
    person takes other's items.
    Note however, that although person may be altered, other remains the same --
    other does not lose its items.    
    """
person.items.update(other.items)
return person
list_people2 = [reduce(take_items, g) for k, g in itertools.groupby(
    list_people, lambda person: person.id)]
for person in list_people2:
    pass
список диктов python, как объединить ключ: значение, где значения одинаковы?