Newbie: conventional instead of recursive way
Anton Vredegoor
anton at vredegoor.doge.nl
Fri Dec 20 09:12:19 EST 2002
On 20 Dec 2002 10:55:40 GMT, Igor Zivkovic <izivkov1 at jagor.srce.hr>
wrote:
>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]
It took me some time to find out what this function does. After some
refactoring it seems to do this:
def printList1(L):
R = L[:]
while R:
x = R.pop(0)
if type(x) == list:
R = x + R
else:
print x,
Regards,
Anton
More information about the Python-list
mailing list