[Tutor] finding duplicates within a tuple of tuples

Norman Khine norman at khine.net
Thu Jul 29 15:52:02 CEST 2010


i have this tuple:


i have this, which does what i want:

from collections import defaultdict

d = defaultdict(set)
for id, url in result:
for url in sorted(d):
	if len(d[url]) > 1:
		print('%d -- %s' % (len(d[url]), url))

so here the code checks for duplicate urls and counts the number of occurences.

but i am sort of stuck in that i want to now update the id of the
related table and update the

basically i have two tables:

id, url
24715L, 'http://aqoon.local/muesli/2-muesli-tropical-500g.html'
24719L, 'http://aqoon.local/muesli/2-muesli-tropical-500g.html'

id, tid,
1, 24715L
2, 24719L

so i want to first update t(2)'s tid to t(1)'s id for each duplicate
and then delete the row id = 24719L


˙uʍop ǝpısdn p,uɹnʇ pןɹoʍ ǝɥʇ ǝǝs noʎ 'ʇuǝɯɐן sǝɯıʇ ǝɥʇ puɐ 'ʇuǝʇuoɔ
ǝq s,ʇǝן ʇǝʎ
%>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or
chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] )

More information about the Tutor mailing list