<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def getHeadingLevel(ts, hierarchy=default_hierarchy):
 """Extract heading level for a particular Tex element, given a specified hierarchy. 2 1 6 """

        try:
            return hierarchy.index(ts.name)+1
        except ValueError:
            if ts.name.endswith('section'):
                i, name = 0, ts.name
                while name.startswith('sub'):
                    name, i = name[3:], i+1
                if name == 'section':
                    return i+2
            return float('inf')
        except (AttributeError, TypeError):
            return float('inf')