【发布时间】:2020-07-21 04:10:15
【问题描述】:
我有一个深度优先搜索算法,它从本体中提取信息。
我有一个工作函数来获取具有特定属性的所有对象,但是,我基本上需要为不同的属性做同样的事情。
如果我有这两个简化的功能,例如
def a():
for n in nodes:
do something with n.property1
def b():
for n in nodes:
do something with n.property2
有没有办法可以将所需的属性作为参数传递?所以我最终得到:
def a(property):
for n in nodes:
do something with n.property
a(property1)
a(property2)
【问题讨论】:
标签: python python-3.x parameters redundancy