python 2 xml 排序并删除重复项

python 2 xml to sort and remove duplicates

如何继续一个代码在打印前排序和删除重复项? type_id 包含多次重复

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from xml.dom.minidom import *
xml = parse('1.xml')
name = xml.getElementsByTagName('type_id')
for node in name:
    print node.childNodes[0].data.encode('utf-8')

由于你的问题很含糊,这里给出一个含糊的答案

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from xml.dom.minidom import *
xml = parse('1.xml')
name = xml.getElementsByTagName('type_id')
hashes = set()
for node in name:
    hashes.add(node.childNodes[0].data.encode('utf-8'))

print "\n".join(sorted(hashes))