New submission from Steven D'Aprano:

According to the documentation, random.shuffle() should accept a sequence. But 
it also accepts dicts, in which case it does nothing, expensively:

py> x = dict.fromkeys(range(10**6))
py> random.shuffle(x)
py> str(x)[:55] + "...}"
'{0: None, 1: None, 2: None, 3: None, 4: None, 5: None, ...}'


I'm not sure if it is better to explicitly test for and reject dicts and 
mappings, or just document that sorting dicts will apparently succeed while 
doing nothing.

Do we want to support sorting OrderedDicts? That at least makes sense, since 
they have an order, but again shuffle() seemingly works but actually does 
nothing.

I lean towards explicitly testing for dicts and raising.

----------
messages: 293265
nosy: rhettinger, steven.daprano
priority: normal
severity: normal
status: open
title: random.shuffle pointlessly shuffles dicts
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue30311>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to