A Mountain of Perl Books + Python Advocacy
Glyph Lefkowitz
glyph at twistedmatrix.com
Thu May 11 21:27:12 EDT 2000
erik_wilsher at my-deja.com writes:
> Having read this, and also noticed a request for
> some sort of "unique" flag for lists in the
> python todo-list, I added a sortlist class to my
> bisect module.
>
> Using this class we can reduce the above program
> to:
>
> --------
> #!/usr/bin/env python
> "uniq.py --Read lines from input file, and write
> sorted output to file"
>
> import fileinput,bisect,sys
>
> uniq=bisect.sortlist(fileinput.input(sys.argv[1]))
> open(sys.argv[2],'w').writelines(uniq.list())
> --------
Okay; I don't have this modified bisect.py, so I can't test this, but
here goes: (documentation omitted ... who needs documentation when
you're talking about perl? :-P)
---
import fileinput,bisect,sys
open(sys.argv[2],'w').writelines(bisect.sortlist(fileinput.input(sys.argv[1])).list())
---
So there. Two lines of python for the whole thing. :-)
and-i-didn't-even-have-to-make-it-more-than-80-characters-long-'ly y'rs,
--
__________________________________________
| ______ __ __ _____ _ _ |
| | ____ | \_/ |_____] |_____| |
| |_____| |_____ | | | | |
| @ t w i s t e d m a t r i x . c o m |
| http://www.twistedmatrix.com/~glyph/ |
`__________________________________________'
More information about the Python-list
mailing list