2017-02-13 63 views
0

我已下令对列表从SymPy求解,[(a,b),(c,d), etc.] 我需要这些值转换为一个列表插入像另一个功能:将sympy有序对转换为列表。

def func1(a, b): 
    do_stuff 
    print_stuff 

我尝试使用list(zip(*foo))但是它返回

[(-1.21566973175616,), (2.39458716469521,)] 

这是无用的。任何帮助将不胜感激,新的python(comp。物理类)。

+0

itertools的伎俩!非常感谢! – zgwolfe

回答

1

如果我理解正确,那么您只需要寻找itertools.chain

>>> l = [(4, 3), (2, 6), (10, 2)] 
>>> list(chain(*l)) 
[4, 3, 2, 6, 10, 2] 
1

我不是100%肯定你问,但我希望这将有助于

lst = [(1,2),(3,4),(5,6)] 

def func1(a,b): 
    stuff = a+b # random 'do_stuff' 
    print(stuff) 

for x in lst: 
    func1(*x) 
# the * will unpack x so that it will be accepted into the foo function, you could also do func1(x[0],x[1])