如何在函数中使用* args和** kargs在Python中传递嵌套列表,元组,集合和字典? [英] How can I pass nested list, tuple, set and dictionary in Python using *args and **kargs in function?
问题描述
def arithmetic_mean(first,* values):
此函数计算非空的算术平均值
任意数量的数值
返回(第一+总和(值))/(1 + len(值))
x = [('a',232),('b',343),('c',543),('d',23)]
y = [[('a', 232),('b',343),('c',543),('d',23)]]
我有什么尝试过:
可以通过zip方式或其他任何方式实现吗?
< blockquote>应该可以,请参阅 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[^].
这篇关于如何在函数中使用* args和** kargs在Python中传递嵌套列表,元组,集合和字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!