[Tutor] List madness

Kirby Urner urnerk@qwest.net
Thu, 07 Mar 2002 10:41:36 -0800


What if you do the below in IDLE?  Just define the
function at a >>> prompt:


 >>> def findit(db, item):
         for each in db:
            thing = re.findall(item, '%s'%each)
            if thing != [] : return each
            else:            return '%s not found, chump.'%item

Then start doing the other lines, one by one:

   >>> list = open('\\list.csv','r')
   >>> listed = list.readlines()

Does "listed" contain what you expect after the readlines?

  >>> looky =  # just give it the string directly
  >>> print findit(listed, looky)

I'd recommend using the above interactively in
IDLE until it works, then memorialize it as a .py
file.

Kirby

"You acknowledge that Software is not designed, licensed
or intended for use in the design, construction, operation
or maintenance of any nuclear facility." -- Java license
agreement