python mutating a list while for loop Error -
all want removing duplicate elements in list l.c(l) working, d(l) shows typeerror: argument of type 'nonetype' not iterable when run it. think there no differences between these 2 functions. can not figure out why comes out type error:
def c(l): l = [] in range(len(l)): if not(l[i] in l): l = l + [l[i]] return l def d(l): l = [] print type(l) in range(len(l)): if not (l[i] in l): l = l.append(l[i]) return l
thanks help.
this:
l = l + [l[i]]
is not equivalent this:
l = l.append(l[i])
the line above assigns l
value return value of calling append
function, none
.
you can use instead:
l.append(l[i])
Comments
Post a Comment