Dictionary to tuple

2005-06-28 Thread Odd-R.
I have a dictionary, and I want to convert it to a tuple, that is, I want each key - value pair in the dictionary to be a tuple in a tuple. If this is the dictionary {1:'one',2:'two',3:'three'}, then I want this to be the resulting tuple: ((1,'one'),(2,'two'),(3,'three')). I have been trying for

Re: Dictionary to tuple

2005-06-28 Thread bruno modulix
Odd-R. wrote: > I have a dictionary, and I want to convert it to a tuple, > that is, I want each key - value pair in the dictionary > to be a tuple in a tuple. > > If this is the dictionary {1:'one',2:'two',3:'three'}, > then I want this to be the resulting tuple: > ((1,'one'),(2,'two'),(3,'three'

Re: Dictionary to tuple

2005-06-28 Thread Jeff Epler
It looks like you want tuple(d.iteritems()) >>> d = {1: 'one', 2: 'two', 3: 'three'} >>> tuple(d.iteritems()) ((1, 'one'), (2, 'two'), (3, 'three')) You could also use tuple(d.items()). The result is essentially the same. Only if the dictionary is extremely large does the difference matter. (or

Re: Dictionary to tuple

2005-06-28 Thread Tim Williams (gmail)
On 28 Jun 2005 14:45:19 GMT, Odd-R. <[EMAIL PROTECTED]> wrote: > I have a dictionary, and I want to convert it to a tuple, > that is, I want each key - value pair in the dictionary > to be a tuple in a tuple. > > If this is the dictionary {1:'one',2:'two',3:'three'}, > then I want this to be the r

Re: Dictionary to tuple

2005-06-28 Thread bruno modulix
Tim Williams (gmail) wrote: (snip) d = {1:'one',2:'two',3:'three'} t = tuple([(k,v) for k,v in d.iteritems()]) Err... don't you spot any useless code here ?-) (tip: dict.items() already returns a list of (k,v) tuples...) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-

Re: Dictionary to tuple

2005-06-28 Thread Erik Max Francis
bruno modulix wrote: > Err... don't you spot any useless code here ?-) > > (tip: dict.items() already returns a list of (k,v) tuples...) But it doesn't return a tuple of them. Which is what the tuple call there does. -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San

Re: Dictionary to tuple

2005-06-28 Thread Robert Kern
Erik Max Francis wrote: > bruno modulix wrote: > >>Err... don't you spot any useless code here ?-) >> >>(tip: dict.items() already returns a list of (k,v) tuples...) > > But it doesn't return a tuple of them. Which is what the tuple call > there does. The useless code referred to was the list

Re: Dictionary to tuple

2005-06-28 Thread Jeremy Sanders
Erik Max Francis wrote: > But it doesn't return a tuple of them. Which is what the tuple call > there does. Yes, but I think he meant: t = tuple(d.items()) -- Jeremy Sanders http://www.jeremysanders.net/ -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionary to tuple

2005-06-28 Thread John Roth
"bruno modulix" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Odd-R. wrote: >> I have a dictionary, and I want to convert it to a tuple, >> that is, I want each key - value pair in the dictionary >> to be a tuple in a tuple. >> >> If this is the dictionary {1:'one',2:'two',3:'three

Re: Dictionary to tuple

2005-06-29 Thread bruno modulix
Erik Max Francis wrote: > bruno modulix wrote: > >> Err... don't you spot any useless code here ?-) >> >> (tip: dict.items() already returns a list of (k,v) tuples...) > > But it doesn't return a tuple of them. Which is what the tuple call > there does. Of course, but the list-to-tuple convers