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)
On 09/08/2022 20:59, Gilles wrote:
On 09/08/2022 10:51, Charlie Clark wrote:
Though, to be honest I suspect writing to a Sqlite database and
exporting unique values back to XML is probably going to be easier.
I found another way, without relying on SQLite:
===============
parser = et.XMLParser(remove_blank_text=True)
tree = et.parse(item,parser)
root = tree.getroot()
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
print(no_dups)
===============
_______________________________________________
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