I created this function sometime ago for my own purposes. It simply flattens a list.
Check out the first comment for another version of someone else's design.
1 2 3 4 5 6 7 8
# flattens a list eg. flatten(1, 2, ['b','a','c']) = [1, 2, 'a', 'b', 'c'] def flatten(*args): for x in args: if hasattr(x, '__iter__'): for y in flatten(*x): yield y else: yield x