Data Structure Question

Mike Johnson ffp_randjohnson at yahoo.com
Sun Jun 17 13:17:07 EDT 2001


In article <V55X6.304885$oc7.24663956 at news2.rdc2.tx.home.com>, "Rainer
Deyke" <root at rainerdeyke.com> wrote:


> Try the other way around, i.e. a dictonary of lists:
> 
> key_value_pairs = [('key1', 'value1'), ('key2', 'value2'), ('key2',
> 'value3')]
> 
> dict = {}
> for key, value in key_value_pairs:
>   dict.setdefault(key, []).append(value)

This works very well! Thank you!

- Mike Johnson


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list