如何将Python中的以下程序更改为函数式样?for循环与函数式编程风格的打印python
from itertools import permutations
for p in permutations(range(1, int(input()) + 1)):
print(*p, sep='')
我知道地图,但
map(lambda p: print(*p, sep=''), permutations(range(1, int(input()) + 1)))
不会产生预期的输出。
我想知道如果不重新定义for循环,是否可以这样做。
你从中得到什么好处? –
https://stackoverflow.com/a/20296780/2308683(和其他答案那里) –
这是我的课程中的一个练习,并且不允许有 –