Skip to content

Commit

Permalink
Update seqmult.py: use lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus authored Feb 12, 2024
1 parent c8c9b7e commit bc46700
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions seqmult.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
#!/usr/bin/env python
# Author Dario Clavijo 2020
from functools import reduce


def SeqMult(s):
mul = lambda a, b: a * b
l = len(s)
while l > 1:
if l & 1 == 1:
s += [1]
l += 1
s = list(map(mul, s[: l // 2], s[l // 2 :]))
l = len(s)
return s[0]
def SeqMult(lst):
return reduce(lambda x, y: x * y, lst)


print((SeqMult([1, 2, 3, 4, 5]) == (1 * 2 * 3 * 4 * 5)))

0 comments on commit bc46700

Please sign in to comment.