Ugh. Reading that was physically painful. This is an excellent example of how not to use list comprehensions.
Here's a strict rewriting that doesn't use list comprehensions:
for i in xrange(0, N):
implicit_list_1 = []
for k in xrange(i):
if now[k] == now[i]:
implicit_list_1.append(i)
if implicit_list_1 == []:
for j in xrange(1, K + 1):
implicit_list_2 = []
for l in xrange(i):
if now[l] == j:
implicit_list_2.append(l)
if implicit_list_2 == []:
And here's a more idiomatic rewriting:
for i in xrange(N):
if now[i] not in now[:i]:
for j in xrange(1, K + 1):
if j not in now[:i]:
This is assuming that K
is a separate variable, and not a mistyped k
.
Also, those one-letter variable names are poor style. Better to use variable names that actually reflect the use of the variable.