It's me wrote:

Okay, I give up.

What's the best way to count number of items in a list [that may contain lists]?


a = [[1,2,4],4,5,[2,3]]

def iterall(seq):
   for item in seq:
       try:
           for subitem in iterall(item):
               yield subitem
       except TypeError:
           yield item

all = [x for x in iterall(a)]
print len(all)

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to