Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- data = (9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
- # --- example 1 ---
- result = 0
- for digit in data:
- result = result*10 + digit
- print(result)
- # --- example 2 ---
- from functools import reduce
- def fun(a, b):
- return a*10+b
- result = reduce(fun, data)
- print(result)
- # --- example 3 ---
- from functools import reduce
- result = reduce(lambda a, b: a*10+b, data)
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement