code: def count_leaves(x):
      
      if hasattr(x, 'keys'):
          x = list(x.values())
      if hasattr(x, '__getitem__'):
          return sum(map(count_leaves, x))
  
      return 1
docs: Return the number of non-sequence items in a given recursive sequence.