File: unsort.py

package info (click to toggle)
python-pyutil 3.3.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 884 kB
  • sloc: python: 7,198; makefile: 6
file content (23 lines) | stat: -rw-r--r-- 505 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# -*- coding: utf-8-with-signature-unix; fill-column: 77 -*-
# -*- indent-tabs-mode: nil -*-

#  This file is part of pyutil; see README.rst for licensing terms.

# randomize the lines of stdin or a file

import random, sys

def main():
    if len(sys.argv) > 1:
        fname = sys.argv[1]
        inf = open(fname, 'r')
    else:
        inf = sys.stdin

    lines = inf.readlines()
    random.shuffle(lines)
    sys.stdout.writelines(lines)

if __name__ == '__main__':
    main()