d = pq(html)
for race_el in d('race'):
    race = pq(race_el)
race_id = race.attr('id')
for nom_el in race.items('nomination'):
    pq(nom_el).attr('raceid', race_id)
PyQuery How do I append and rename an element into each of its subelements