<div>Thanks Alan, but can you please explain me what this line does:</div>
<div>diff = [t1==t2 for t1,t2 in zip(line1,line2)].index(False)<br>&nbsp;</div>
<div><br><br>&nbsp;</div>
<div><span class="gmail_quote">On 10/6/06, <b class="gmail_sendername">Alan Gauld</b> &lt;<a href="mailto:alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt; wrote:</span>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Some general thoughts:<br><br>&gt; import sys<br>&gt; from stringCompare import stringcmp&nbsp;&nbsp; # this is a module which has
<br>&gt; stringcmp<br>&gt;<br>&gt; fname1 = raw_input(&quot;Enter a file name to be read:\t&quot;)<br>&gt; fname2 = raw_input(&quot;Enter a file name to be read:\t&quot;)<br>&gt;<br>&gt; fd1 = open(fname1,&quot;r&quot;)<br>
&gt; fd2 = open(fname2,&quot;r&quot;)<br>&gt;<br>&gt;<br>&gt; done = False<br><br>Use Boolean value instead of 1/0<br><br>&gt; line_counter = 0<br>&gt; while not done:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;aLine1 = fd1.readline()<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;aLine2 = 
fd2.readline()<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;if (aLine1 == &quot;&quot; or aLine2 == &quot;&quot;):&nbsp;&nbsp;# test whether you have<br>&gt; reached the<br>&gt; end of file<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;done = 1<br><br>assign directly to done, using a boolean test:
<br><br>done = not (aLine1 and aLine2)<br><br>and miss out the if/else test.<br><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;line_counter += 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # get the line number<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string1 = aLine1.split()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # split the line into a
<br>&gt; list containing words<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string2 = aLine2.split()<br><br>Not sure why you are splitting the lines into words.<br>You call them columns but they are really words of<br>varying length. Why not just compare the lines as a whole?
<br><br>if aLine1 != aLine2:<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;The difference lies in line&quot;, line_counter<br><br>Then you can find the first characters that differ:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;diff = [t1==t2 for t1,t2 in zip(line1,line2)].index(False)
<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;and start at character&quot;, diff<br><br>It's not exactly equivalent to your code of course but it seems to me<br>to be more accurate...<br><br>If you must use words, apply the spolit only when you know its needed:
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;words1 = aLine1.split()<br>&nbsp;&nbsp;&nbsp;&nbsp;words2 = aLine2.split()<br>&nbsp;&nbsp;&nbsp;&nbsp;diff = [w1==w2 for w1,w2 in zip(words1,words2)].index(False)<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;and start at word&quot;,diff<br><br>HTH,<br><br><br>--<br>Alan Gauld
<br>Author of the Learn to Program web site<br><a href="http://www.freenetpages.co.uk/hp/alan.gauld">http://www.freenetpages.co.uk/hp/alan.gauld</a><br><br><br>_______________________________________________<br>Tutor maillist&nbsp;&nbsp;-&nbsp;&nbsp;
<a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br><br clear="all"><br>-- <br>To HIM you shall return.