[Tutor] searching for a string in a dictionary
John Fouhy
john at fouhy.net
Wed Aug 9 09:41:56 CEST 2006
On 09/08/06, Alan Gauld <alan.gauld at freenet.co.uk> wrote:
> > all_types:
> > <Storage {'type': 'childcare', 'id': 1, 'created':
> > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}>
> > <Storage {'type': 'household', 'id': 2, 'created':
> > datetime.datetime(2006, 7, 26, 15, 18, 34, 887436)}>
> > .....
> > <Storage {'type': 'knews', 'id': 10, 'created':
> > 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 list in any sense that Python will recognise.
> Can you show us the actual data structures please?
I think what he wants is:
if 'teststring' in [s.type for s in all_types]
...
--
John.
More information about the Tutor
mailing list