Answers for "how to pick random element from list python without using choice function"

12

how to print a random part of a list in python

import random

foo = ['a', 'b', 'c', 'd', 'e']
print(random.choice(foo))
Posted by: Guest on April-08-2020
23

how to randomly choose from a list python

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

python choose random sample from list

import random
sequence = [i for i in range(20)]
subset = random.sample(sequence, 5) #5 is the lenth of the sample
print(subset) # prints 5 random numbers from sequence (without replacement)
Posted by: Guest on November-19-2020

Code answers related to "how to pick random element from list python without using choice function"

Python Answers by Framework

Browse Popular Code Answers by Language