有没有一种方法可以在具有多个属性的用户定义Python对象列表上迭代和调用函数?假设它被称为Entry,属性名称和年龄。映射/遍历Python对象列表
,这样我可以说的东西的
def func(name, age):
//do something
def start(list_of_entries)
map(func, list_of_entries.name(), list_of_entries.age())
//but obviously the .name and .age of the object, not the iterable
//these are the only two attributes of the class
效果想使用functools.partial(),但不知道这是即使在这种情况下,有效的。
在'func'中访问'name'和'age'是否有原因? –
为什么不把list_of_entries中的每个条目都传递给func(),然后通过传入的对象访问name/age? –
来计算:“list_of_entries.name()”你可以使用map! –