import random
input_list = [1, 3, "rand", 2]
output_list = []
options = set(range(5))
for item in input_list:
if item == "rand":
new_variable = random.choice(list(options))
else:
new_variable = item
output_list.append(new_variable)
options -= set([ new_variable ])
. , , , , .
set
, , . , , choice
set
. , , .
, , , (, randint(0, 100000)
99990 ). .
, , :
def fill_randoms(list_with_randoms, options):
for item in list_with_randoms:
value = random.choice(list(options)) if item == 'rand' else item
yield value
options -= set([ value ])
:
list(fill_randoms([1, 3, "rand", 2], set(range(5))))
, .