[issue43618] random.shuffle loses most of the elements

2021-03-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: As an immediate fix to your problem, replace this line: random.shuffle(questions_element) with: questions = list(questions_element) random.shuffle(questions) questions_element[:] = questions -- ___

[issue43618] random.shuffle loses most of the elements

2021-03-25 Thread Stefan Behnel
Stefan Behnel added the comment: Yes, this is neither a bug in CPython (or its stdlib) nor in lxml. It's how things work. Don't use these two together. -- resolution: -> third party stage: -> resolved status: open -> closed ___ Python tracker

[issue43618] random.shuffle loses most of the elements

2021-03-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: Interestingly, this isn't an LXML bug. It is a documented difference from how the standard library works: https://lxml.de/tutorial.html#elements-are-lists So, if you want use random.shuffle(), you need the standard library ElementTree instead of lxm

[issue43618] random.shuffle loses most of the elements

2021-03-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: The standard library isn't at fault here. Please file this an an LXML bug. Reproducer: from lxml.etree import Element root = Element('outer') root.append(Element('zero')) root.append(Element('one')) root.append(Element('two')) pri

[issue43618] random.shuffle loses most of the elements

2021-03-24 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +skrah ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.py

[issue43618] random.shuffle loses most of the elements

2021-03-24 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue43618] random.shuffle loses most of the elements

2021-03-24 Thread Tim Peters
Tim Peters added the comment: Are you sure it's "a list"? At least print out `type(questions_element)`. `random.shuffle()` doesn't contain any code _capable_ of changing a list's length. It only does indexed accessing of the list: ... for i in reversed(range(1, len(x))): # pick a

[issue43618] random.shuffle loses most of the elements

2021-03-24 Thread Eric V. Smith
Eric V. Smith added the comment: Same advice as issue 43616: please provide an example we can run. This most likely a problem with how you're using lxml, and not a bug in python. But since we can't test it, we can't know for sure. -- nosy: +eric.smith ___

[issue43618] random.shuffle loses most of the elements

2021-03-24 Thread Irit Katriel
Change by Irit Katriel : -- components: +Library (Lib) ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https:

[issue43618] random.shuffle loses most of the elements

2021-03-24 Thread Rowan Sylvester-Bradley
New submission from Rowan Sylvester-Bradley : This issue is probably related to issue ??? but I have created it as a separate issue. When shuffle doesn't crash it sometimes (or maybe always - I haven't fully analysed this yet) looses most of the elements in the list that it is supposed to be