[Tutor] First code snipet

Alan Gauld alan.gauld at btinternet.com
Sun Jul 26 09:39:31 CEST 2009


"Darth Kaboda" <darthkaboda at msn.com> wrote

> The one worry I have is not coding things the Phython way
> ...So would like to have people look at a simplistic class


>         rpile = pile1[0:0] #get blank copy of the passed in object types.

This will return an empty list regardless of the type of passed in object.
The only possible difference is a subclassed list but if its been well
implemented you shouldn't care! I'd just go with:

rpile = []

>             for x in range(0,i):

Its usual in Python to omit the first 0

for x in  range(i):

is all that's needed.

Otherwise it looks OK to me.

You might be able to leverage the stdlib more effectively, for
example there is a shuffle type menthod for randomising a
single list. And zip() to merge two lists...

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 




More information about the Tutor mailing list