有沒有一種方法可以在具有多個屬性的用戶定義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! –