def __str__(self):
def hill_sorted_elements(values):<EOL><INDENT>def element_sort_key(pair):<EOL><INDENT>element, value = pair<EOL>if isinstance(element, Atom):<EOL><INDENT>return <NUM_LIT:0>, element.symbol<EOL><DEDENT>elif isinstance(element, Radical):<EOL><INDENT>return <NUM_LIT:1>, element.symbol<EOL><DEDENT>else:<EOL><INDENT>return <NUM_LIT:2>, None<EOL><DEDENT><DEDENT>if Atom.C in values:<EOL><INDENT>yield Atom.C, values[Atom.C]<EOL>if Atom.H in values:<EOL><INDENT>yield Atom.H, values[Atom.H]<EOL><DEDENT>for element, value in sorted(<EOL>iteritems(values), key=element_sort_key):<EOL><INDENT>if element not in (Atom.C, Atom.H):<EOL><INDENT>yield element, value<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for element, value in sorted(<EOL>iteritems(values), key=element_sort_key):<EOL><INDENT>yield element, value<EOL><DEDENT><DEDENT><DEDENT>s = '<STR_LIT>'<EOL>for element, value in hill_sorted_elements(self._values):<EOL><INDENT>def grouped(element, value):<EOL><INDENT>return '<STR_LIT>'.format(element, value if value != <NUM_LIT:1> else '<STR_LIT>')<EOL><DEDENT>def nongrouped(element, value):<EOL><INDENT>return '<STR_LIT>'.format(element, value if value != <NUM_LIT:1> else '<STR_LIT>')<EOL><DEDENT>if isinstance(element, Radical):<EOL><INDENT>if len(element.symbol) == <NUM_LIT:1>:<EOL><INDENT>s += nongrouped(element, value)<EOL><DEDENT>else:<EOL><INDENT>s += grouped(element, value)<EOL><DEDENT><DEDENT>elif isinstance(element, Atom):<EOL><INDENT>s += nongrouped(element, value)<EOL><DEDENT>else:<EOL><INDENT>s += grouped(element, value)<EOL><DEDENT><DEDENT>return s<EOL>
Return formula represented using Hill notation system

        >>> str(Formula({Atom.C: 6, Atom.H: 12, Atom.O: 6}))
        'C6H12O6'