Python 如何将函数的结果用作同一函数的参数?

Python 如何将函数的结果用作同一函数的参数?,python,function,recursion,Python,Function,Recursion,我想使用相同的功能,但不是硬编码,因为我使它。 基本上我想在一个新函数中模拟最后5行。 请帮助使用循环: from itertools import chain, zip_longest number_of_cards = int(input()) indexes = [3,3,2] deck = [i for i in range(1, number_of_cards + 1)] def func(lst, index): shuffle1 = lst[:index] s

我想使用相同的功能,但不是硬编码,因为我使它。 基本上我想在一个新函数中模拟最后5行。 请帮助使用循环:

from itertools import chain, zip_longest

number_of_cards = int(input())
indexes = [3,3,2]

deck = [i for i in range(1, number_of_cards + 1)]

def func(lst, index):
    shuffle1 = lst[:index]
    shuffle2 = lst[index:]
    res = []
    for val in list(chain(*zip_longest(shuffle1,shuffle2))):
        if val != None:
            res.append(val)
    return res

a = func(deck, 0)
b = func(a,1)
c = func(b,2)
d = func(c,3)
print(d)

你不需要递归<对于范围(4)中的i,代码>结果=组和
:结果=函数(结果,i)
for i in range(4):
    deck = func(deck, i)