NEWB: General purpose list iteration?
Devan L
devlai at gmail.com
Thu Aug 11 23:37:59 EDT 2005
def descend(iterable):
if hasattr(iterable, '__iter__'):
for element in iterable:
descend(element)
else:
do_something(iterable)
This will just do_something(object) to anything that is not an
iterable. Only use it if all of your nested structures are of the same
depth.
If you used it on the following list of lists
[[something],[[something_else],[other_thing]]]
it would modify something, something_else, and other_thing.
More information about the Python-list
mailing list