I want to mix the list that stores the objects.
random.shuffle
I don't know why, but None
keeps returning, so I can't write it.
I think it's because there's an object in the list, not a normal type like int
Is there any other way to mix the list elements other than random.shuffle
?
import random
class a:
foo = "bar"
a1 = a()
a2 = a()
b = [a1,a2]
print random.shuffle(b)#None
random.shuffle can be written even if the element in the list is an object of a user-defined class.
This is the case when the print
is wrong.
shuffle
is not the result of mixing, but None
is returned
print random.shuffle(b)
of course prints None
.
To output normally
import random
class a:
foo = "bar"
a1 = a()
a2 = a()
b = [a1,a2]
random.shuffle(b)
for i in b:
print i.foo
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.