+ 3

To randomize the items of a list

I have written a code. is it correct? or can there be some more logical way? thanx https://code.sololearn.com/crzsl7GOHll1/?ref=app

28th Jan 2019, 5:50 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
6 Respostas
+ 4
You could get it shorter, but more shorter means not better. import random as r l=[18,64,648,83,"hello","bye"] print(r.choice(l)) I think your code is okay.
29th Jan 2019, 7:06 AM
Sven_m
Sven_m - avatar
+ 4
It looks very nice. Just a little comment, choice and shuffle work different, choice returns a random element of the list and shuffle randomize all the list. So I wouldn't change the shuffle for choice, unless I require a single element instead of the whole list
29th Jan 2019, 11:37 PM
Laura Madrigal
Laura Madrigal - avatar
+ 3
28th Jan 2019, 6:10 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 2
Your code is very good, it does not need to be improved!😀
28th Jan 2019, 6:06 PM
giannismach
giannismach - avatar
+ 2
Nilutpol Kashyap You 're welcome!
28th Jan 2019, 6:11 PM
giannismach
giannismach - avatar
30th Jan 2019, 9:25 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar