<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def count_leaves(x):
 """ Return the number of non-sequence items in a given recursive sequence. """

    if hasattr(x, 'keys'):
        x = list(x.values())
    if hasattr(x, '__getitem__'):
        return sum(map(count_leaves, x))

    return 1