+ 1

How can I print random elements in a list?

List = ["string", "word", "type"]

24th Jul 2020, 2:44 PM
Aphiwe Ayanda Khumalo
4 Answers
+ 5
If you are looking to get more than 1 random element from an iterabe, you can use choices() instead: from random import choices lst = [2,4,11,9,5,2,8] print(choices(lst,k=3)) # k is the number of elements to return by choices
24th Jul 2020, 3:29 PM
Lothar
Lothar - avatar
+ 3
Import random random.choice(List) if this isn't what you are looking for ,let me know
24th Jul 2020, 3:07 PM
Abhay
Abhay - avatar
+ 2
Abhay Thanks this is exactly what I was looking for
24th Jul 2020, 3:20 PM
Aphiwe Ayanda Khumalo
+ 1
https://code.sololearn.com/cuBqKS6TmrzB/?ref=app You can check my project to know some more ...
25th Jul 2020, 4:02 PM
Ath Tripathi
Ath Tripathi - avatar