Answers for "python random items from list"

33

python choose random element from list

import random

#1.A single element
random.choice(list)

#2.Multiple elements with replacement
random.choices(list, k = 4)

#3.Multiple elements without replacement
random.sample(list, 4)
Posted by: Guest on May-25-2020
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
0

random from list python

random.choice(seq)¶
Return a random element from the non-empty sequence seq.
Posted by: Guest on October-30-2021

Code answers related to "python random items from list"

Python Answers by Framework

Browse Popular Code Answers by Language