<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def used_states(self):
        'a list of the used states in the order they appear'
        c = itertools.count()
        canonical_ids = collections.defaultdict(lambda: next(c))
        for s in self.states_list:
            for state in s.stateseq:
                canonical_ids[state]
        return list(map(operator.itemgetter(0),
                sorted(canonical_ids.items(),key=operator.itemgetter(1))))