>if result not in result_set: Есть же встроенный set, зачем так?А ещё есть random.sample:)
import sys import os import getopt import random def usage(): print('Usage: %s [-h|--help] [-s|--string string] 5x36' % sys.argv[0]) if __name__ == '__main__': try: opts, args = getopt.gnu_getopt(sys.argv[1:], "hs:", ['help', 'string=']) string = None for o, a in opts: if o in ('-h', '--help'): usage() sys.exit(0) elif o in ('-s', '--string'): string = a else: print('Unhandled option. Wow. How?') sys.exit(1) if len(args) != 1 or 'x' not in args[0]: usage() sys.exit(1) count, max_num = [int(i) for i in args[0].split('x')] seed = string if string is not None else os.urandom(256) random.seed(seed) print('%s\nYour numbers: %s' % (args[0], str(random.sample(range(1, max_num + 1), count)))) except getopt.GetoptError: usage() sys.exit(1) except Exception as e: print('Error: %s' % unicode(e)) sys.exit(1)
Re:Про Python и спортлото
>if result not in result_set:
Есть же встроенный set, зачем так?
А ещё есть random.sample:)
Emacs-w3m/1.4.468 w3m/0.5.3