Python - What do these two lines do? -
being new python, i'm having heck of time figuring out these 2 lines do:
for in [j j in xrange(0, n) if [k k in xrange(j) if now[k] == now[j]] == []]: j in [k k in xrange(1, k + 1) if [l l in xrange(i) if now[l] == k] == []]:
is there way rewrite noobs myself understand it? thanks.
i'm positive code equivalent to:
for in range(0, n): prefix = set(now[:i]) if now[i] in prefix: continue j in range(1, k + 1): if j in prefix: continue #
or (which bit less efficient, nicely reflects idea behind code):
for i, j in itertools.product(range(0, n), range(1, k + 1)): prefix = now[:i] if now[i] not in prefix , j not in prefix: # , j
but it's written in convulted, inefficient way (especially [...] == []
nasty , pointless). maybe feels pretty clever using complex structures simple ones better suited.
Comments
Post a Comment