[Tutor] python coding using regular expression

Kent Johnson kent37 at tds.net
Thu Dec 21 12:08:55 CET 2006

sg wrote:
> hi,,,,
>      i am new to python. i want help in regular expression.. anyone explain
> or guide me for following problem..
> the content of txt file is splitted using the pipe | symbol and sorted .
> then the field in the first row is compared with field in the second row and
> the second row field is compared with third and so on till end of file.. if
> there is mismatch between the row, the error will be throw as follows..
> For example,
> david thomson
> davis thomson
>  in above string 'd' and 's' are mismatched.. so the error will be thrown.

I don't think you need regular expressions for this. What do you mean by 
mismatched? any difference between them, or something more subtle?

If you compare the first row to the second, the second to the third, 
etc, then you will get the error unless every line is the same. Is that 
what you want?

If I understand you, what you want to do can be done with a simple loop 
over the lines with a variable that remembers the value of the previous 


More information about the Tutor mailing list