[issue43618] random.shuffle loses most of the elements

Raymond Hettinger report at bugs.python.org
Thu Mar 25 13:30:54 EDT 2021


Raymond Hettinger <raymond.hettinger at gmail.com> 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'))
    print([e.tag for e in root])
    root[1], root[0] = root[0], root[1]
    print([e.tag for e in root])

This outputs:

   ['zero', 'one', 'two']
   ['one', 'two']

Replacing the import with:

   from xml.etree.ElementTree import Element

Gives the expected result:

   ['zero', 'one', 'two']
   ['one', 'zero', 'two']

----------
nosy: +scoder -skrah

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43618>
_______________________________________


More information about the Python-bugs-list mailing list