Last active
February 27, 2017 15:45
-
-
Save msuzen/823e2c26d702fa222aa61b7564c23b57 to your computer and use it in GitHub Desktop.
An example on using arbitrary number of arguments with Python 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
(c) 2017 | |
Creative Commons Licence | |
This work is licensed under a Creative Commons Attribution 3.0 Unported License. | |
""" | |
import functools as ft | |
# Example on using arbitrary number of arguments | |
def msum(*nums): | |
''' | |
msum takes arbitrary number of | |
arguments and sum them ups. | |
''' | |
add = lambda x, y : x+y | |
return(ft.reduce(add, nums)) | |
msum(2,6,7) # 15 | |
msum(8,6,9,20,31) # 74 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment