Vinay的答案应该仍然有效,但是对于Python 2.7+和3.2+,建议以下操作:parent_map = {c:p for p in tree.iter() for c in p}getiterator()不推荐使用iter(),而推荐使用新的dict列表理解构造函数。其次,在构造XML文档时,一个孩子可能会有多个父母,尽管一旦您序列化该文档,该父母就会被删除。如果那很重要,您可以尝试以下方法:parent_map = {}for p in tree.iter(): for c in p: if c in parent_map: parent_map[c].append(p) # Or raise, if you don't want to allow this. else: parent_map[c] = [p] # Or parent_map[c] = p if you don't want to allow this