In [1]:
import random
In [2]:
l = [0, 1, 2, 3, 4]
In [3]:
print(random.sample(l, 3))
In [4]:
print(type(random.sample(l, 3)))
In [5]:
print(random.sample(l, 1))
In [6]:
print(random.sample(l, 0))
In [7]:
# print(random.sample(l, 10))
# ValueError: Sample larger than population or is negative
In [8]:
print(random.sample(('xxx', 'yyy', 'zzz'), 2))
In [9]:
print(random.sample('abcde', 2))
In [10]:
print(tuple(random.sample(('xxx', 'yyy', 'zzz'), 2)))
In [11]:
print(''.join(random.sample('abcde', 2)))
In [12]:
l_dup = [0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]
In [13]:
print(random.sample(l_dup, 3))
In [14]:
print(set(l_dup))
In [15]:
print(random.sample(set(l_dup), 3))