[Tutor] python coding using regular expression

Luke Paireepinart rabidpoobear at gmail.com
Thu Dec 21 12:05:28 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.
>
>   
This sounds to me like a homework problem.
In any case, there's no reason to use regexps here. 
If you're checking for _any_ difference between two strings, you can 
just use the regular comparison operator:
 >>> 'david thomson' == 'davis thomson'
False

Unless you have some other requirements you haven't mentioned.
HTH,
-Luke


More information about the Tutor mailing list