import xml.dom.minidom andmed={} sonad=["hei", "hi", "heinad"] for sona in sonad: plokk=andmed for taht in sona: if taht in plokk: plokk[taht]["kogus"]+=1 else: plokk[taht]={'kogus':1} plokk=plokk[taht] d=xml.dom.minidom.Document() p=d.createElement("s") p.setAttribute("sisu", "algus") d.appendChild(p) def kannaYle(solm, xmlSolm): for voti in solm: if not voti=="kogus": p2=d.createElement("s") p2.setAttribute("sisu", voti) p2.setAttribute("kogus", str(solm[voti]["kogus"])) xmlSolm.appendChild(p2) kannaYle(solm[voti], p2) kannaYle(andmed, p) print(d.toxml()) def tryki(solm, tase): for voti in solm: if not voti=="kogus": print(tase*" ", voti, solm[voti]["kogus"]) #kuvage ka kogus tryki(solm[voti], tase+1) #tryki(andmed, 0)