0
N = int(input())
q = []
x=list(input())
a,b,c=x[0],x[1],x[2]                                  
q.insert(0,'a')
q.insert(0,'c')
q.insert(1,'b')
print(q)` 

我希望输出为 [6, 5, 10] 我如何专门从列表中获取值并将其插入到另一个列表中还有一种方法 x 根本不是列表

4

1 回答 1

0

您需要拆分输入并使用变量更改 listName.insert 值。

'a' 与 a 不同。第一个是字符,第二个是变量。

q = []
x=list(input("Enter three values separated with space: ").split())
a,b,c=x[0],x[1],x[2] 
q.insert(0,a)
q.insert(0,c)
q.insert(1,b)
print(q)

输出:

Enter three values separated with space: 
1 2 3
['3', '2', '1']

另一件事,N 是一个未使用的变量。

于 2021-10-13T15:13:35.773 回答