【发布时间】:2014-04-20 07:38:09
【问题描述】:
以下函数(在 Python 中实现)的好名字是什么?
def a_function(element, a_set):
if a_set[0] == element:
return a_set[1]
if a_set[1] == element:
return a_set[0]
assert 'A' == a_function('B', ['A', 'B'])
【问题讨论】:
-
我的
super_magical_awesome_comparison_and_validator_function(element, a_set)。只是在开玩笑。只需执行get_not之类的操作 -
怎么样
a_set[not a_set.index(element)]:D -
@hllau 你有一个小问题,Python 有一个
set,但这不是你使用的......我也会重命名参数。 -
@jonrsharpe:欢迎指正,虽然这不是问题的重点。
-
@hilau
pair相当中立,很容易表示,你不觉得吗?
标签: python function naming-conventions naming