这是我到目前为止的代码
print("L = ",[4,10,4,2,9,5,4])
Startlist = [4,10,4,2,9,5,4]
usrinput = int(input("Enter an element to search for in the list: "))
for i in [i for i,x in enumerate(Startlist) if x == usrinput]:
print(i)
但是,我正在尝试从 for 循环打印的数字中创建一个新列表。这是我通过输入 4 得到的示例运行
L = [4, 10, 4, 2, 9, 5, 4]
Enter an element to search for in the list: 4
0
2
6
我怎么能把 0 2 6 变成 [0,2,6]?
感谢您的任何回复