Thanks for the info. I already adopted a program from another person and it works like a charm. As for your question, I had no idea of if I had duplicate or more as there was some 570 line items. I whittled it down to 370 line entries. Whew.

Ken

Luke Paireepinart wrote:


On Sat, Mar 20, 2010 at 11:34 AM, Ken G. <beach...@insightbb.com <mailto:beach...@insightbb.com>> 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.  Can the same file
    be opened and read two times within a program?

    For example, a file has:

    1
    2
    2
    3
    4
    4
    5
    6
    6

    The newly revised file should be:

    1
    2
    3
    4
    5
    6

    Again, thanking the group for their input,


One-liner:
open("output.txt", "w").write("\n".join(sorted(set([i.strip() for i in open("input.txt")]))))


Just for fun :)

also, in your algorithm, why are you assuming there are at most 1 extra entries in the case of a duplicate? Why not generalize it for all duplicates?
-Luke

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to