<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2730.1700" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>WAIDW == (W)hat (A)m (I) (D)oing
(W)rong</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>(Question put short:</FONT></DIV>
<DIV>Why does this function return; None?</DIV>
<DIV><FONT face=Arial size=2>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV><FONT face=Arial size=2>def shuffle(i=24, deck=[]):</FONT></DIV>
<DIV><FONT face=Arial size=2> a = [ace, 2, 3, 4, 5, 6, 7, 8,
9, 10, jack, queen, king]<BR>
deck.append(a[:])<BR> print deck<BR> if i
> 0:</FONT></DIV>
<DIV><FONT face=Arial size=2> print "if i
> 0"<BR> shuffle(i-1, deck)</FONT></DIV>
<DIV><FONT face=Arial size=2> elif i == 0:</FONT></DIV>
<DIV><FONT face=Arial size=2> print "elif i
== 0"<BR> print deck</FONT></DIV>
<DIV><FONT face=Arial size=2>
return deck<BR> else: print "failsafe"</FONT></DIV>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV> </DIV>
<DIV>Read below for more detailed describtion of my wrong doings ;)</DIV>
<DIV>)</DIV></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>I'm trying to create a list representing
a stack of cards containing six card decks, I do not really care much of
the about colour so my stack would come to look like this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV><FONT face=Arial size=2>stack = [[ace, 2, 3,....., king], [ace, 2, 3,.....,
king],........,[ace, 2, 3,...., king]</FONT></DIV>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>The above should symbolise a list (stack) with 24
lists of different colours (allthough the colours e.g. clubs or hearts, are not
shown as such).</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Now call me lazy but I would prefer not to type all
those those identical lists manually (both easthatically and labour wise),
so I saw this as a good time to try to play around with recursive
functions (easily done in a forloop with two lines, but now I'm stubborn).
</FONT></DIV>
<DIV><FONT face=Arial size=2>The best bit of code I have come up with untill now
is this:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV><FONT face=Arial size=2>def shuffle(i=24, deck=[]):</FONT></DIV>
<DIV><FONT face=Arial size=2> a = [ace, 2, 3, 4, 5, 6, 7, 8,
9, 10, jack, queen, king]<BR>
deck.append(a[:])<BR> print deck<BR> if i
> 0:</FONT></DIV>
<DIV><FONT face=Arial size=2> print "if i
> 0"<BR> shuffle(i-1, deck)</FONT></DIV>
<DIV><FONT face=Arial size=2> elif i == 0:</FONT></DIV>
<DIV><FONT face=Arial size=2> print "elif i
== 0"<BR> print deck</FONT></DIV>
<DIV><FONT face=Arial size=2>
return deck<BR> else: print "failsafe"</FONT></DIV>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV><FONT face=Arial size=2>(The print statements are for testing)</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>Which of course doesn't work (Otherwise I
wouldn't be writing this mail)!</FONT></DIV>
<DIV><FONT face=Arial size=2>The the output ends up like this:</FONT></DIV>
<DIV><FONT face=Arial size=2>[[11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10,
10]]<BR>if i > 0<BR>[[11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10], [11, 2, 3,
4, 5, 6, 7, 8, 9, 10, 10, 10, 10]]</FONT></DIV>
<DIV><FONT face=Arial size=2>if i > 0</FONT></DIV>
<DIV><FONT face=Arial size=2>etc. etc.</FONT></DIV>
<DIV><FONT face=Arial size=2>These few lines above shows me that everything
shaping about nicely, the list is looking the way it's supposed to.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>In the end of the output i finally equals 0, and
the list is printed a final time looking complete (len(deck) == 24). When the
next command in the sourcecode reads: return deck.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>###</FONT></DIV>
<DIV><FONT face=Arial size=2>elif i == 0:</DIV>
<DIV><FONT face=Arial size=2> print "elif i ==
0"<BR> print deck</FONT></DIV>
<DIV><FONT face=Arial size=2>
return deck<BR>###</FONT></DIV>
<DIV> </DIV>
<DIV>My question is this:</DIV>
<DIV>If the list "deck" is as it is supposed to (and it looks to be), then why
does the function return; None?</DIV>
<DIV> </DIV>
<DIV>In advance thanks for any enlightment.</DIV>
<DIV> </DIV></FONT></BODY></HTML>