I'm -1 too. Making ordered containers to sequence-like only for random.choice is a wrong idea.
If random.choice should support non-sequence ordered container, just propose it to random.choice. And if the proposal was rejected, you can do it by yourself with helper functions. >>> import random >>> from itertools import islice >>> def nth(iterable, n): ... return next(islice(iterable, n, None)) >>> def choice_from_container(c): ... return nth(c, random.randrange(len(c))) >>> d = dict.fromkeys(range(10000)) >>> choice_from_container(d) 61 >>> choice_from_container(d) 9858 >>> choice_from_container(d.keys()) 2436 >>> choice_from_container(d.items()) (7685, None) -- Inada Naoki <[email protected]> _______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/XEXTKEOLJBNWHYPUQMGFTNN4SZQHWLMH/ Code of Conduct: http://python.org/psf/codeofconduct/
