[Tutor] searching for a string in a dictionary

anil maran anilmrn at yahoo.com
Wed Aug 9 11:59:53 CEST 2006


doesTypeExist=filter(lambda x: typeofstring in x.type, all_types)

 if 'teststring' in [s.type for s in all_types]
this works which is better in terms of speed???

for+in or filter+lambda

thanks a lot

Alan Gauld <alan.gauld at freenet.co.uk> wrote: 
> On 09/08/06, Alan Gauld  wrote:
>> > all_types:
>> > 
>> > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}>
>> >
>> > how do i search for a particular string say teststring in this 
>> > list
>>

> I think what he wants is:
>
>    if 'teststring' in [s.type for s in all_types]

But type is still not accessible as an attribute.
It looked to me like he wanted a list of dictionaries
in which case it wouyld be:

if teststring in [s['type'] for s in all_types]

But the submitted data is not in any usable format so far
as Python is concxerned and the data structure will be
critical to how the code works.

Anil, we need to get more specific information from you
about your code and error messages, we can't guess
what you have done.

Alan G 



 				
---------------------------------
Want to be your own boss? Learn how on  Yahoo! Small Business. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060809/a5094310/attachment.htm 


More information about the Tutor mailing list