Answers for "random choise from list in python"

23

how to randomly choose from a list python

random.choice(name of list)
Posted by: Guest on December-04-2019
0

randomly pick a value in the list

import random

l = [0, 1, 2, 3, 4]

print(random.sample(l, 3))
# [1, 3, 2]

print(type(random.sample(l, 3)))
# <class 'list'>
Posted by: Guest on August-26-2021

Code answers related to "random choise from list in python"

Python Answers by Framework

Browse Popular Code Answers by Language