Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread Alan Gauld
> 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??? These do two different things. The first returns a list of all_types entries that match The second returns true or false if *any*

Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread anil maran
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+lambdathanks a lotAlan Gauld <[EMAIL PROTECTED]> wrote: > On 09/08/06, Alan Gauld <[EMAIL PROTECTED]> wrote:>> > all_types:

Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread anil maran
if teststring in [s['type'] for s in all_types]:                print 'contained'            else:                print 'notcontained'this workedthanks a lot guyspyTutor rocksAlan Gauld wrote: > On 09/08/06, Alan Gauld <[EMAIL PROTECTED]> wrote:>> > all_types:>> > >> > datetime.datetime(2006, 7, 2

Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread John Fouhy
On 09/08/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > 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] Err, that is what I meant :-) -- John.

Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread Alan Gauld
> On 09/08/06, Alan Gauld <[EMAIL PROTECTED]> 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_type

Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread John Fouhy
On 09/08/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > all_types: > > > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}> > > > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}> > > . > > > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}> > > there is such a list > > > > how do i s

Re: [Tutor] searching for a string in a dictionary

2006-08-09 Thread Alan Gauld
> all_types: > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}> > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}> > . > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}> > there is such a list > > how do i search for a particular string say teststring in this list This isn't a l