mylist = ['a','b','c','d']
How can I index the list so that I choose only two of the four elements? mylist[]
throws all sorts of errors depending what datatype I put in the square brackets for indexing
mylist = ['a','b','c','d']
How can I index the list so that I choose only two of the four elements? mylist[]
throws all sorts of errors depending what datatype I put in the square brackets for indexing
You can use random.sample
Try this:
import random
mylist = ['a','b','c','d']
print(random.sample(mylist, 2))