I am very new to Python (and coding in general). I am trying to create a function which creates a duplicate of a list, with any instances of the string "rand" replaced with a random integer. The function will be called several times, with a new input_list each time. These new items should be appended to the existing output list. We can assume there will be no repeated integers, but the "rand" string may appear many times. This is my current code. It does very close to what I want except that when the random number is already on the list, it just moves on to the next item rather than trying to create a new random number. Can anyone help me out with this? Thank you in advance.
import random
input_list = [1, 3, "rand", 2]
def number_adder(input_list):
output_list = []
for item in my_list:
if item == "rand":
new_variable = int(random.randint(0, 4))
if new_variable in output_list:
continue
else:
new_variable = item
output_list.append(new_variable)
return output_list
==thusif item == "rand".output_list = item)?