Re: dictionary with tuple keys

2009-12-15 Thread John Machin
Ben Finney ben+python at benfinney.id.au writes: In this case, I'll use ‘itertools.groupby’ to make a new sequence of keys and values, and then extract the keys and values actually wanted. Ah, yes, Zawinski revisited ... itertools.groupby is the new regex :-) Certainly it might be clearer

Re: dictionary with tuple keys

2009-12-15 Thread Brandon Devine
So grateful! Thanks to all. The breadth of Python continues to amaze me, as does your generosity. (Relative clarity like relative beauty is in the eye of the beholder, and few parents have ugly children... fantastic!) Brandon -- http://mail.python.org/mailman/listinfo/python-list

dictionary with tuple keys

2009-12-14 Thread Brandon Devine
Hi all, I am probably not thinking straight anymore about this problem. I have a dictionary with tuple keys in the format (a, b, A, B) and float values. I want to collect all the keys with identical (a, b...), disregarding whatever (... A, B) might be. Specifically, I want to sum the float

Re: dictionary with tuple keys

2009-12-14 Thread Chris Rebert
On Mon, Dec 14, 2009 at 9:49 PM, Brandon Devine your.mas...@gmail.com wrote: Hi all, I am probably not thinking straight anymore about this problem.  I have a dictionary with tuple keys in the format (a, b, A, B) and float values.  I want to collect all the keys with identical (a, b

Re: dictionary with tuple keys

2009-12-14 Thread Ben Finney
Brandon Devine your.mas...@gmail.com writes: I am probably not thinking straight anymore about this problem. I have a dictionary with tuple keys in the format (a, b, A, B) and float values. I want to collect all the keys with identical (a, b...), disregarding whatever (... A, B) might

Re: dictionary with tuple keys

2009-12-14 Thread Paul Rubin
Brandon Devine your.mas...@gmail.com writes: I am probably not thinking straight anymore about this problem. I have a dictionary with tuple keys in the format (a, b, A, B) and float values. I want to collect all the keys with identical (a, b...), disregarding whatever (... A, B) might

printing dictionary and tuple

2008-03-19 Thread Beema shafreen
Hi everbody i am trying to print the dictionary values and tuple in a same line as below print \t.join(dict[a].values())+'\t'+\t.join(b) Error I get is the TypeError, since i have misisng values in the dictionary. if i use exception i will miss those how should i print the data without

Re: printing dictionary and tuple

2008-03-19 Thread Gabriel Genellina
En Wed, 19 Mar 2008 08:16:52 -0300, Beema shafreen [EMAIL PROTECTED] escribió: i am trying to print the dictionary values and tuple in a same line as below print \t.join(dict[a].values())+'\t'+\t.join(b) Error I get is the TypeError, since i have misisng values in the dictionary

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 conversion is not

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 if

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

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[::-1] for 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 Jose,

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'}, then I