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]
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
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
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
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]:
...
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