Re: [Zope] ZCatalog results.
Sidnei da Silva <sidnei@x3ng.com.br> writes:
Im trying to make 2 searchs on one ZCatalog and merge both into a single result, but I had no success on removing the duplicated results.
The straightforward approach: Supposing you have objectID as MetaData identifier in your ZCatalog: results = ....your search here seen = [] uniqresult = [] for result in results: if result.objectID not in seen: seen.append(result.objectID) uniqresult.append(result) Many optimizations possible :) Regards, Frank -- CTO fte@Lightwerk.com http://www.Lightwerk.com/ Fax: +49-2434-80 07 94 Phone: +49-2434-80 07 81 Lightwerk GmbH * An der Kull 11 * 41844 Wegberg * Germany Besuchen Sie uns auf der CeBIT: Halle 6, Stand F68 / 595
On Sat, Feb 23, 2002 at 01:08:11PM +0100, Frank Tegtmeyer wrote:
for result in results: if result.objectID not in seen:
Instead of "seen" just use dictionary. Oleg. -- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
On Sun, Feb 24, 2002 at 12:46:03PM +0100, Frank Tegtmeyer wrote:
Instead of "seen" just use dictionary.
Which dictionary do you mean? Or was meant "just use a dictionary"?
Yes, just use a dictionary. Hash lookups are *much* faster than linear search that "in" does. Oleg. -- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
Something like this, i presume. seen = {} unique = [] for r in result: if not seen.has_key(r.data_record_id_): seen[r.data_record_id_] = r.data_record_id_ unique.append(r) return unique It works OK. Thanx everyone. Em Dom 24 Fev 2002 12:12, Oleg Broytmann escreveu:
On Sun, Feb 24, 2002 at 12:46:03PM +0100, Frank Tegtmeyer wrote:
Instead of "seen" just use dictionary.
Which dictionary do you mean? Or was meant "just use a dictionary"?
Yes, just use a dictionary. Hash lookups are *much* faster than linear search that "in" does.
Oleg.
-- Sidnei da Silva X3ng Web Technology sidnei@x3ng.com.br
Sidnei da Silva <sidnei@x3ng.com.br> writes:
seen = {} unique = [] for r in result: if not seen.has_key(r.data_record_id_): seen[r.data_record_id_] = r.data_record_id_ unique.append(r)
return unique
It works OK. Thanx everyone.
You may reduce this to one dictionary :) Regards, Frank
How? Em Seg 25 Fev 2002 13:52, Frank Tegtmeyer escreveu:
Sidnei da Silva <sidnei@x3ng.com.br> writes:
seen = {} unique = [] for r in result: if not seen.has_key(r.data_record_id_): seen[r.data_record_id_] = r.data_record_id_ unique.append(r)
return unique
It works OK. Thanx everyone.
You may reduce this to one dictionary :)
Regards, Frank
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Sidnei da Silva X3ng Web Technology sidnei@x3ng.com.br
On Tue, Feb 26, 2002 at 01:02:28PM -0300, Sidnei da Silva wrote:
How?
seen = {} unique = [] for r in result: if not seen.has_key(r.data_record_id_): seen[r.data_record_id_] = r.data_record_id_ unique.append(r)
return unique
It works OK. Thanx everyone.
You may reduce this to one dictionary :)
You want "unique" to contain unique records? The list of keys of a dictionary is exactly what you want! unique = {} for r in result: if not unique.has_key(r.data_record_id_): unique[r.data_record_id_] = r return unique.values() The "if" test is not neccessary, actually :) Oleg. -- Oleg Broytmann http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
Excuse me for my ignorance. I should have realized this at first sight, but i think i need to wash my face more strongly when i wake up.... []'s Sidnei. Em Ter 26 Fev 2002 13:16, Oleg Broytmann escreveu:
On Tue, Feb 26, 2002 at 01:02:28PM -0300, Sidnei da Silva wrote:
How?
seen = {} unique = [] for r in result: if not seen.has_key(r.data_record_id_): seen[r.data_record_id_] = r.data_record_id_ unique.append(r)
return unique
It works OK. Thanx everyone.
You may reduce this to one dictionary :)
You want "unique" to contain unique records? The list of keys of a dictionary is exactly what you want!
unique = {} for r in result: if not unique.has_key(r.data_record_id_): unique[r.data_record_id_] = r return unique.values()
The "if" test is not neccessary, actually :)
Oleg.
-- Sidnei da Silva X3ng Web Technology sidnei@x3ng.com.br
participants (3)
-
Frank Tegtmeyer -
Oleg Broytmann -
Sidnei da Silva