Re: Not this one the other one, from a dictionary

2009-09-22 Thread Sion Arrowsmith
Vlastimil Brom vlastimil.b...@gmail.com wrote: other_key = (set(data_dict.iterkeys()) - set([not_wanted_key,])).pop() other_key = set(data_dict.iterkeys()).difference([not_wanted]).pop() saves you the construction of an unnecessary set instance. At the cost of a bit more verbosity, you can get

Re: Not this one the other one, from a dictionary

2009-09-22 Thread Jean Daniel
Building on the answers of the others, a simple one liner, no side effect, not the fastest I guess: d={'a': 'bob', 'b': 'stu'} set( d.keys() ).difference( [ 'a' ] ).pop() 'b' Note the square brackets for the parameter of difference(). 'The string 'a' and the list [ 'a' ] are both iterable but

Re: Not this one the other one, from a dictionary

2009-09-22 Thread Vlastimil Brom
Thanks for the elaboration; in retrospect, given the simple requirement, that there are only two dict keys, one of which is know and the other to be determined, maybe just the direct dict methods are appropriate, e.g. d = {'a': 'bob', 'b': 'stu'} d_copy = dict(d) d_copy.pop(a) 'bob'

Re: Not this one the other one, from a dictionary

2009-09-18 Thread Tim Chase
Learning my way around list comprehension a bit. I wonder if someone has a better way to solve this issue. I have a two element dictionary, and I know one of the keys but not the other, and I want to look up the other one. Several ways occur to me. Of the various solutions I played

Re: Not this one the other one, from a dictionary

2009-09-18 Thread Ishwor
Ross Hi. So I have this dictionary: aDict = {'a': 'bob', 'b': 'stu'} Yes. I know that the dictionary contains two keys/value pairs,  but I don't know the values nor that the keys will be 'a' and 'b'.   I finally get one of the keys passed to me as variable BigOne. e.g.: BigOne = a

Re: Not this one the other one, from a dictionary

2009-09-18 Thread Ross
Thanks Tim (and Ishwor) for the suggestions, those are structures that somewhat new to me - looks good! I'll play with those.At this rate I may soon almost know what I'm doing. Rgds Ross. On 18-Sep-09, at 1:19 PM, Tim Chase wrote: Learning my way around list comprehension a bit. I

Re: Not this one the other one, from a dictionary

2009-09-18 Thread Vlastimil Brom
2009/9/18 Ross ros...@gmail.com: Learning my way around list comprehension a bit.   I wonder if someone has a better way to solve this issue.  I have a two element dictionary, and I know one of the keys but not the other, and I want to look up the other one. So I have this dictionary: