From SETL to Python translation
Marcin 'Qrczak' Kowalczyk
qrczak at knm.org.pl
Tue Mar 13 13:22:16 EST 2001
Mon, 12 Mar 2001 00:55:06 -0500, Tim Peters <tim.one at home.com> pisze:
> > if #(odds := {x in nodes | odd(#G{x})}) > 2 then
>
> is the Python:
>
> odds = []
> for x in nodes:
> successors = [y for (z, y) in G if z == x]
> if len(successors) % 2:
> odds.append(x)
> if len(odds) > 2:
Or:
def successors(G, x): return [y for (z, y) in G if z == x]
odds = [x for x in nodes if len(successors(G, x)) % 2]
if len(odds) > 2:
--
__("< Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZASTĘPCZA
QRCZAK
More information about the Python-list
mailing list