[Tutor] Clean up loop and search in a list

Kent Johnson kent37 at tds.net
Fri Oct 14 03:44:29 CEST 2005

Markus Rosenstihl wrote:
> Thank you  for the fast reply
> Am 13.10.2005 um 19:43 schrieb Kent Johnson:
>>  if len(filter(re_name.search, line)) > 0:
>>could be written
>>  if re_name.search(line):
> this is not working  because I am parsing a line in a list (i think):

Ah, sorry, I misunderstood - line is a list of strings, not a single string.

Can the name really appear in any field? Or could you use
  if re_name.search(line[4]) # (or whatever the correct field number)

>>or even, since the re is just fixed text,
>>  if phone[name] in line:

This should be 
  if phone[name] in line[4]

>>>Is there for example a way to search the whole list and give back all
>>>the line numbers containing a string?
>>  [ i for i, line in enumerate(rechnung) if "Monatliche" in line ]

  [ i for i, line in enumerate(rechnung) if "Monatliche" in line[0] ]


More information about the Tutor mailing list