且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在函数中使用* args和** kargs在Python中传递嵌套列表,元组,集合和字典?

更新时间:2023-11-29 07:54:58

应该可以,请参阅 https://docs.python.org/3.4/tutorial/ controlflow.html#keyword-arguments [ ^ ]。

def arithmetic_mean(first, *values):
""" This function calculates the arithmetic mean of a non-empty
arbitrary number of numerical values """

return (first + sum(values)) / (1 + len(values))

x= [('a', 232), ('b', 343), ('c', 543), ('d', 23)]
y= [[('a', 232), ('b', 343), ('c', 543), ('d', 23)]]

What I have tried:

can it be possible by zip method or any other way possible?

It should be possible, see https://docs.python.org/3.4/tutorial/controlflow.html#keyword-arguments[^].