
On 10/08/2022 13:30, Charlie Clark wrote:
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.
Just a few ten's, so performance isn't an issue for me. Indeed, I changed the code since I don't actually care about the three infos, just if that block has already been see or not: #remove dups no_dups = [] for row in tree.iter("wpt"): lat,lon = row.attrib.values() if lat not in no_dups: no_dups.append(lat) else: row.getparent().remove(row)