Skip to content

Commit

Permalink
luhn: fix lambda usage (see exercism#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
behrtam committed Jan 25, 2016
1 parent 8dc1d9f commit c31cf1f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion luhn/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ def __init__(self, number):
self.number = number

def addends(self):
def luhn_transform(n):
return (2 * n - 9) if (n > 4) else (2 * n)
old_digits = [int(d) for d in str(self.number)]
luhn_transform = lambda n: (2 * n - 9) if (n > 4) else (2 * n)
return [(luhn_transform(n) if (i % 2 == 0) else n)
for i, n in enumerate(old_digits, start=len(old_digits) % 2)]

Expand Down

0 comments on commit c31cf1f

Please sign in to comment.