Python:用另一个列表中的元素替换列表中的元素

Python:用另一个列表中的元素替换列表中的元素,python,list,Python,List,我有一个列表,它是用户输入多少个单元格。假设用户输入4,列表将由4个0组成:list\u 1=[0,0,0,0] 现在,用户还被询问要用1替换这些零中的哪一个(必须选择2),并输入:12。我希望list_1[1]和list_1[2]从0更改为1 我尝试了一些不同的方法,但没有一种方法能给我预期的输出,它应该是一个列表[0,1,1,0](如果我使用上述代码) 非常感谢您的帮助。请附上代码。您能告诉我们到目前为止您都做了哪些尝试吗?为什么会有这么多的反对票?马里恩和我按他们的要求给了OP我不知道为什

我有一个列表,它是用户输入多少个单元格。假设用户输入4,列表将由4个0组成:
list\u 1=[0,0,0,0]

现在,用户还被询问要用1替换这些零中的哪一个(必须选择2),并输入:
12
。我希望
list_1[1]
list_1[2]
从0更改为1

我尝试了一些不同的方法,但没有一种方法能给我预期的输出,它应该是一个列表
[0,1,1,0]
(如果我使用上述代码)


非常感谢您的帮助。

请附上代码。您能告诉我们到目前为止您都做了哪些尝试吗?为什么会有这么多的反对票?马里恩和我按他们的要求给了OP我不知道为什么人们会这样做?只需点击downvote,即使它是错误的,也不需要提及任何理由来纠正。当我们的两个代码都完美运行时,这尤其令人恼火。。。并回答OP的问题请解释你的答案,而不是仅仅转储一个代码片段。
num_zero = int(input("Please enter the number of 0s")) #note this is python3
list_1 = num_zero*[0] #creates a list with the inputted number of zeroes
indices = input("Enter list indices: i j") #get string with two numbers in it sep by space
indices = indices.split(" ")  # create array with number strings
for s in indices: 
    i = int(s) #turn each number string into an int
    list_1[i] = 1 #set the specified indices of the list of zeroes to 1
num_zero = input('Enter number of zeros you want in a list:')
zero_list = [0 for i in range(num_zero)]
indices = raw_input('Enter the indices you want to convert separated by space:')
index_list = map(int, indices.split())
for i in index_list:
    zero_list[i] = 1