lists + string

Mark McEahern marklists at mceahern.com
Fri May 10 11:55:46 EDT 2002


[ian]
> input = str(raw_input .........
>
> how do i compare it to an element in a list??
>
> ive tried
>
> for x in list
>     if input == x:print 'found item'
>
> but it dont work any help would be great thanx

Python encourages you to use good form when formatting your code.  Note the
missing : at the end of your for statement.

By the way, it's always a good idea when posting a question about code
that's broken to provide a full example of the code that's broken.  You
wrote, "it don't work", but you don't tell us what isn't working, what are
the symptoms of failure, etc.

Also, you don't show us sample input or a sample list.  We have to guess
this for ourselves.

Help us help you.  Chances are, if you do that, you'll end up helping
yourself eventually.

Cheers,

// mark






More information about the Python-list mailing list