Я пытаюсь сделать python list comprehension
, но я получаю синтаксическую ошибку. Я не знаком с python list comprehension
, поэтому я не могу понять, почему это ошибка.python list comprehension function синтаксическая ошибка
>>> s = set()
>>> def in_set(s, val):
if val in s:
return True
else:
s.add(val)
return False
>>> [x for x in v0.outV() if x.eid not in_set(s, x.eid)]
File "<input>", line 1
[x for x in v0.outV() if x.eid not in_set(s, x.eid)]
^
SyntaxError: invalid syntax
>>> print "This Works"
This Works
>>> in_set(s, v0.eid)
False
v0.outV()
является generator
, x
является object
и x.eid
является string
.
Я думаю, вы имеете в виду 'if not in_set (s, x.eid)'. – BrenBarn