Skip to content

Instantly share code, notes, and snippets.

@msuzen
Last active February 27, 2017 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msuzen/823e2c26d702fa222aa61b7564c23b57 to your computer and use it in GitHub Desktop.
Save msuzen/823e2c26d702fa222aa61b7564c23b57 to your computer and use it in GitHub Desktop.
An example on using arbitrary number of arguments with Python 3
"""
(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