how to change order of attributes of an element using beautiful soup

Solutions on MaxInterview for how to change order of attributes of an element using beautiful soup by the best coders in the world

showing results for - "how to change order of attributes of an element using beautiful soup"
Alfonso
12 Aug 2018
1from simplified_scrapy.simplified_doc import SimplifiedDoc
2html ='''
3<word form="συ" head="2610" id="2357" lemma="συ" postag="p-s----n-" relation="ExD_AP"/>
4'''
5def toString(ele):
6  order = ['id','head','postag','from','lemma','relation']
7  result = '<'+ele.tag
8  for p in order:
9    result+=' {}="{}"'.format(p,ele[p])
10  return result+'/>'
11doc = SimplifiedDoc(html)
12ele = doc.word
13print (toString(ele))
14