469,358 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

flatten sequences in a dictionary

Hi

I wondering if someone could give me a pointer. I have a dictionary
with the following structure:

testDict = dict(foo=((1,2,3),(1,4,3)), bar=((3,2,1),(9,8,7,)),
mumble=((1,2,3),))

I am trying to create a list of the the 3 element tuples using
itertools (just for a bit of fun). I'm trying this:

list(itertools.chain(testDict.itervalues())

but that's doesn't work. I think I need a way to convert the iterator
returned by itervalues() into a sequence of iterables. Any clues?

Thanks

Andy
Jan 9 '08 #1
1 1150
On Jan 9, 1:16 pm, ajcpp...@gmail.com wrote:
Hi

I wondering if someone could give me a pointer. I have a dictionary
with the following structure:

testDict = dict(foo=((1,2,3),(1,4,3)), bar=((3,2,1),(9,8,7,)),
mumble=((1,2,3),))

I am trying to create a list of the the 3 element tuples using
itertools (just for a bit of fun). I'm trying this:

list(itertools.chain(testDict.itervalues())
Close! Try:
list(itertools.chain(*testDict.itervalues())

--
Paul Hankin
Jan 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

23 posts views Thread by Francis Avila | last post: by
10 posts views Thread by bearophile | last post: by
18 posts views Thread by Ville Vainio | last post: by
32 posts views Thread by Robin Becker | last post: by
18 posts views Thread by psbasha | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.