Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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))
Comment

random array in python

import random
Items = ["Item1", "Item2", "Item3", "Item4", "Item5"]
print(random.choice (Items))
Comment

python random item of an array

import random
random.choice (mylist)
Comment

PREVIOUS NEXT
Code Example
Python :: generate python date list 
Python :: python levenshtein distance 
Python :: python random randint except a number 
Python :: django-admin command not found 
Python :: pandas astype string 
Python :: python calculate computation time 
Python :: Install requests-html library in python 
Python :: first position dict python 
Python :: negative cv2 
Python :: pandas determine percentage of nans in column 
Python :: human readable time difference python 
Python :: chromebook install pip 
Python :: python datetime module print 12 hour clock 
Python :: python remove first and last character from string 
Python :: py get days until date 
Python :: shift elements in list python 
Python :: list to json python 
Python :: python datetime to string iso 8601 
Python :: add all string elements in list python 
Python :: when did guido van rossum create python 
Python :: how to append to every second item in list python 
Python :: tensorflow turn off gpu 
Python :: argparse mutually exclusive 
Python :: python cd to script directory 
Python :: how to print numbers from 1 to 20 in python 
Python :: python check if hotkey pressed 
Python :: name exit not defined python 
Python :: matplotlib matrix plot 
Python :: pprint python 
Python :: how to do forward feature selection in python 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =