danger of recursive functions

前端 未结 4 1372
清酒与你
清酒与你 2021-01-05 05:03

Often people say that it\'s not recommended to use recursive functions in python (recursion depth restrictions, memory consumption, etc)

I took a permutation example

4条回答
  •  伪装坚强ぢ
    2021-01-05 05:27

    I can't reproduce your timing results (in Python 2.6.1 on Mac OS X):

    >>> import itertools, timeit
    >>> timeit.timeit('list(all_perms("0123456789"))', 
    ...               setup='from __main__ import all_perms'),
    ...               number=1)
    2.603626012802124
    >>> timeit.timeit('list(itertools.permutations("0123456789"))', number=1)
    1.6111600399017334
    

提交回复
热议问题