some_list = [ [ ], [ ], [ ] ]
def my_func(sum):
...
a = 0
b = 1
return a, b
我试图通过从some_list
和a
获取索引来附加到b
中的给定索引。
我需要写些什么才能使下面的代码起作用?
some_list[a].append(win)
some_list[b].append(loss)
答案 0 :(得分:1)
一次将两个变量分配给函数调用,如下所示:
some_list = [ [ ], [ ], [ ] ]
def my_func(sum):
...
a = 0
b = 1
return a, b
a, b = my_func(sum) # this here
some_list[a].append(win)
some_list[b].append(loss)
答案 1 :(得分:0)
假设“工作”是指您要将函数的返回值用作数组的索引。
a, b = my_func(whatever)
some_list[a].append(win)
some_list[b].append(loss)
答案 2 :(得分:0)
some_list = [ [ ], [ ], [ ] ]
def my_func(sum):
a = 0
b = 1
return a, b
sum = 5
a,b = my_func(sum)
win = 'aaa'
loss = 'bbb'
some_list[a].append(win)
some_list[b].append(loss)
print(some_list)