Firstly, I'm a python beginner and just stuck at simple thing.
I want to replace some of my elements in a list with randomly created numbers (by index), according to my values in another list.
Expected output will be like: [3,2,2,1,3]
My code at below totally doesn't work in the way it should.
ori = [4,1,2,1,3] # some elements inside need to be changed
num_list = [2,1,1,1] # numbers that represent index in ori
import random
for num in range(len(num_list)):
ori[num-1]= random.randint(1,4)
# I want to replace element with previous one from given index
print(ori)
range(len(ifnum_listis already the indices to modify? Probably you should not allow duplicate indices innum_listas well (e.g. use asetinstead of alist)num_listto get the values for modifying