[Tutor] Searching list items.

Luke Paireepinart rabidpoobear at gmail.com
Tue Oct 17 23:51:11 CEST 2006

Chris Hengge wrote:
> contents = readlines(myfile, 'r')
> Ok, I'm under the impression this is a list of strings (array)
Nope.  No such thing as arrays in Python.
It is a list of strings, that's it. :)
> How in the world do I cycle through them looking for words?
> for line in contents:
>      if line.contains("something")
>          print line
> Thats a mock up of what I'm looking for.
> I tried to figure out how to use re, but that spits out locations in 
> memory or none it seems.
You'd use regular expressions or use
if 'astring' in line:

if your use case is simple enough for that.
show us what RE you used that gave you trouble.
It's hard to help when we don't know where you're getting stuck :)
> Thanks.


More information about the Tutor mailing list