Re: How to turn a list of tuples into a dictionary?

2008-02-26 Thread castironpi
On Feb 26, 11:15 am, mrstephengross <[EMAIL PROTECTED]> wrote: > > How about this? > >   d = dict(tuples) > > Aha! I hadn't realized it could be so simple. > > --Steve In terms of a metric for code, 'And runs in a single line!' may be a bit deceptive. [Counterexample snipped.] Absent repeating t

Re: How to turn a list of tuples into a dictionary?

2008-02-26 Thread mrstephengross
> How about this? > d = dict(tuples) Aha! I hadn't realized it could be so simple. --Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: How to turn a list of tuples into a dictionary?

2008-02-26 Thread D'Arcy J.M. Cain
On Tue, 26 Feb 2008 09:00:54 -0800 (PST) mrstephengross <[EMAIL PROTECTED]> wrote: > Let's say I've got a list of tuples, like so: > > ( ('a', '1'), ('b', '2'), ('c', '3') > > And I want to turn it into a dictionary in which the first value of > each tuple is a key and the second value is a val

Re: How to turn a list of tuples into a dictionary?

2008-02-26 Thread Paul Rubin
mrstephengross <[EMAIL PROTECTED]> writes: > ( ('a', '1'), ('b', '2'), ('c', '3') I'm not trying to be snide, but have you tried looking in the manual? See http://python.org/doc/lib and look at the section about built-in types, if you want to know things about tuples or dictionaries. -- http:/

Re: How to turn a list of tuples into a dictionary?

2008-02-26 Thread castironpi
On Feb 26, 11:00 am, mrstephengross <[EMAIL PROTECTED]> wrote: > Let's say I've got a list of tuples, like so: > >   ( ('a', '1'), ('b', '2'), ('c', '3') > > And I want to turn it into a dictionary in which the first value of > each tuple is a key and the second value is a value, like so: > >   { '

How to turn a list of tuples into a dictionary?

2008-02-26 Thread mrstephengross
Let's say I've got a list of tuples, like so: ( ('a', '1'), ('b', '2'), ('c', '3') And I want to turn it into a dictionary in which the first value of each tuple is a key and the second value is a value, like so: { 'a' -> '1', 'b' -> '2', 'c' -> '3' } Is there a way to do this with a single