Вы можете использовать XPath
//h2[not(./span)]/a
^ h2 is the container for the entire link plus Ad icon
^ exclude h2s with SPAN children since they contain the Ad icons
^ what you DO want is the A result (hyperlink)
. Таким же образом, просто используйте его имя.
>>> def g(x):
... g.r = 4
...
>>> g
<function g at 0x0100AD68>
>>> g(3)
>>> g.r
4
Если вы пытаетесь выполнить мемоизацию, вы можете использовать словарь в качестве параметра по умолчанию:
def f(x, memo={}):
if x not in memo:
memo[x] = x + 3
return memo[x]
Or use a closure:
def gen_f():
memo = dict()
def f(x):
try:
return memo[x]
except KeyError:
memo[x] = x + 3
return f
f = gen_f()
f(123)
Somewhat nicer IMHO