On 10 Aug 2022, at 9:53, Gilles wrote:

> An important line was missing :-/
>
> no_dups = {}
>
> for row in tree.iter("wpt"):
>
>     name,lat,lon = [row.find("name").text] + row.attrib.values()
>
>     if name not in no_dups:
>
>         no_dups[name] = lat,lon
>
>     else:
>
>         #dup = remove
>
>         row.getparent().remove(row)

Yes, this should work. However, I don't know if adjusting the tree while 
looping over it won't the same kind of problems as with other sequences in 
Python.

How many elements are there in your tree? Memory use in XML can get very 
expensive so combining iterparse with xmlfile would be an alternative. Also, if 
you're only interested in duplicate names, use a set rather than a dictionary.

Charlie

--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Sengelsweg 34
Düsseldorf
D- 40489
Tel: +49-203-3925-0390
Mobile: +49-178-782-6226
_______________________________________________
lxml - The Python XML Toolkit mailing list -- lxml@python.org
To unsubscribe send an email to lxml-le...@python.org
https://mail.python.org/mailman3/lists/lxml.python.org/
Member address: arch...@mail-archive.com

Reply via email to