Dict to "flat" list of (key,value)
David C. Fox
davidcfox at post.harvard.edu
Wed Jul 30 22:57:04 CEST 2003
David C. Fox wrote:
Oops - a mistake and an omission
> 4. and then reduce that to a list of tuples with
> reduce(operator.add, lol)
You need to import the operator module first.
> def flatten(u):
> if isinstance(u, type()):
> return (u, [u])
> return map(lambda x: (u, x), u)
I got my cases reversed - that should be "if not isinstance...
More information about the Python-list