[Tutor] Finding duplicates entry in file

Ken G. beachkid at insightbb.com
Sat Mar 20 18:06:25 CET 2010


Thanks!  You gave me something to do for the rest of the afternoon.

Ken

Steven D'Aprano wrote:
> On Sun, 21 Mar 2010 03:34:01 am Ken G. wrote:
>   
>> What is a method I can use to find duplicated entry within a sorted
>> numeric file?
>>
>> I was trying to read a file reading two lines at once but apparently,
>> I can only read one line at a time.
>>     
>
> f = open("myfile")
> while True:
>     first = f.readline()  # Read one line.
>     second = f.readline()  # And a second.
>     process(first)
>     process(second)
>     if second == '':
>         # If the line is empty, that means we've passed the
>         # end of the file and we can stop reading.
>         break
> f.close()
>
>
>   
>   
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100320/b5338fe1/attachment.html>


More information about the Tutor mailing list