Newbie: conventional instead of recursive way
Igor Zivkovic
izivkov1 at jagor.srce.hr
Fri Dec 20 05:55:40 EST 2002
Thank you for the help. I was trying to insert the whole top element in
the list until I realized that I really need to insert top element's
elements using reversed indexing so they come out in proper order. This
proves the tutorial's statement that the same function can be written
using loops. Once again, I'm not saying its better than recursive
solution. It was just an exercise. :)
def printList(List):
L = List[:]
while L:
if type(L[0]) == list:
tmp = L[:1]
del L[0]
for i in range(1, len(tmp[0]) + 1):
L.insert(0, tmp[0][-i])
else:
print L[0],
del L[0]
--
Igor
More information about the Python-list
mailing list