[issue30311] random.shuffle pointlessly shuffles dicts

2017-05-08 Thread Raymond Hettinger
Raymond Hettinger added the comment: I concur with Tim. These are just duck-typing facts of life. -- resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker

[issue30311] random.shuffle pointlessly shuffles dicts

2017-05-08 Thread Tim Peters
Tim Peters added the comment: Generally speaking, trying to shuffle a dict D already blows up, unless D's keys are the integers range(len(D)). In that case, D is indistinguishable from a list in the sense that both map range(N) to values via __getitem__. `shuffle()` does no type checks whats

[issue30311] random.shuffle pointlessly shuffles dicts

2017-05-08 Thread Martin Panter
Martin Panter added the comment: It is also pointless to shuffle a list object repeating the same item, but that is no reason to add a special case. Is there a real problem with allowing dictionaries and OrderedDict? It seems to behave sensibly if you give each item a unique value: >>> D = {i

[issue30311] random.shuffle pointlessly shuffles dicts

2017-05-08 Thread Steven D'Aprano
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,