Re: searching a list of dictionaries for an element in a list.

2005-08-10 Thread Sion Arrowsmith
Dan <[EMAIL PROTECTED]> wrote: >> [ someone else wrote: ] >> I want to search list1, and the result should be all dictionaries where >> primarycolor is in input. I can do this using a double for-loop, but is >> there a more efficent way? > >Of course.:-) > >L = [dict for dict in list1 if dict[

Re: searching a list of dictionaries for an element in a list.

2005-08-10 Thread Dan
> I want to search list1, and the result should be all dictionaries where > primarycolor is in input. I can do this using a double for-loop, but is > there a more efficent way? Of course.:-) L = [dict for dict in list1 if dict['primarycolor'] in input] In older versions of Python, we would u

searching a list of dictionaries for an element in a list.

2005-08-10 Thread Odd-R.
If input is ['red','blue'], list1 is [ {'primarycolor':'red', 'secondarycolor':'burgundee'}, {'primarycolor':'red', 'secondarycolor':'wine'}, {'primarycolor':'yellow','secondarycolor':'plain'}, {'primarycolor':'blue','secondarycolor':'ocean'}] I