Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Adam Bark
On 15/09/10 15:31, Hs Hs wrote: Dear Steven, Thanks for your help. however I have a question, using: for key, value in xdic.items(): if 1 in value and 2 in value or 3 in value: print key also print keys that have values such as [1,2,3]. In cases where there is [1,2,3] and [1,2]

Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Evert Rol
gt; 75797987:[3,1] > how can I force this. > > thanks again. > > > > > > From: Steven D'Aprano > To: tutor@python.org > Sent: Wed, September 15, 2010 7:27:05 AM > Subject: Re: [Tutor] selecting elements from dictionary > > On Wed, 15 S

Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Hs Hs
M Subject: Re: [Tutor] selecting elements from dictionary On Wed, 15 Sep 2010 12:10:59 pm Hs Hs wrote: > I want to print only those items that have [1,2] and [1,3] in any > order, such as [1,2] or [2,1], [3,1] or [1,3] > > >>> for item in xdic.keys(): > > ... if [1

Re: [Tutor] selecting elements from dictionary

2010-09-15 Thread Steven D'Aprano
On Wed, 15 Sep 2010 12:10:59 pm Hs Hs wrote: > I want to print only those items that have [1,2] and [1,3] in any > order, such as [1,2] or [2,1], [3,1] or [1,3] > > >>> for item in xdic.keys(): > > ... if [1,2] in xdic[item]: > ... print item > > I get a wrong answer, That's bec

Re: [Tutor] selecting elements from dictionary

2010-09-14 Thread Knacktus
xdic {11135457: [1], 11135492: [1], 11135913: [1], 11135436: [1, 2], 11135699: [1, 2], 11135702: [1, 3], 11135901: [1]} I want to print only those items that have [1,2] and [1,3] in any order, such as [1,2] or [2,1], [3,1] or [1,3] >>> for item in xdic.keys(): ... if [1,2] in xdic[item]: ...

[Tutor] selecting elements from dictionary

2010-09-14 Thread Hs Hs
dear group: I have a dictionary object that looks like this: xdic {11135457: [1], 11135492: [1], 11135913: [1], 11135436: [1, 2], 11135699: [1, 2], 11135702: [1, 3], 11135901: [1]} I want to print only those items that have [1,2] and [1,3] in any order, such as [1,2] or [2,1], [3,1] or [1