下面是我的错误代码:
n = int(input())
coins = list(map(int,input().split()))
workertype = list(map(int,input().split()))
a1 = []
a2 = []
a3 = []
for i in range(n):
if(workertype[i]==1):
a1.append(coins[i])
elif(workertype[i]==2):
a2.append(coins[i])
elif(workertype[i]==3):
a3.append(coins[i])
print(a1,a2,a3)
coins
和
workertype
是两个长度相等的列表。我想要列表
a1
使列表中的这些元素
硬币
其指数为
1
列表中有(所有1个)
工作类型
。
与相同
a2
和
a3
但对所有人来说
2
s和
3
s
这是我的输出
1(#input for n)
5 6 7 5 9 10 8(#coins)
1 2 3 3 2 2 1(#workertype)
[5] [] [](a1, a2, a3)
相反,我希望a1、a2、a3分别为[5,1]、[6,9,10]、[7,5]。