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
"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
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
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
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
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[::-
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
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
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'
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
10 matches
Mail list logo