Answers for "get 3 random elements from list python"

9

how to get a random element from an array in python

import random
names=['Mark', 'Sam', 'Henry']

#Set any array
random_array_item=random.choice(names)

#Declare a variable as a random choice
print(random_array_item)

#Print the random choice
#Or, if you want to arrange them in any order:
for j in range(names):
  print(random.choice(names))
Posted by: Guest on June-16-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
1

how to create obtain any random 3 items of list in python

import random as R
A=['a','b','c','d','e','f','g','h','i','j']
print("\n",R.sample(A,3))
Posted by: Guest on June-09-2021

Code answers related to "get 3 random elements from list python"

Python Answers by Framework

Browse Popular Code Answers by Language