Perfect numbers: Difference between revisions

m
→‎{{header|Python}}: Updated a primitive ( concatMap )
m (→‎{{header|Python}}: Updated a primitive ( concatMap ))
Line 2,325:
Or, a little faster (by restricting the search space):
 
<lang python>from mathitertools import (sqrtchain)
from math import (sqrt)
 
 
Line 2,345 ⟶ 2,346:
lows + concatMap(
lambda x: (
lambda y=(n / x): [y] if x != y else []
if x != y
else []
)()
)(lows)
Line 2,358 ⟶ 2,357:
# concatMap :: (a -> [b]) -> [a] -> [b]
def concatMap(f):
defreturn lambda go(xs): list(
a = []chain.from_iterable(
for x in map(f, xs:)
a = a + f(x)
return a)
return lambda xs: go(xs)
 
 
Line 2,371 ⟶ 2,369:
 
 
if __name__ == '__main__':
main()</lang>
{{Out}}
<pre>[6, 28, 496, 8128]</pre>
9,655

edits