OMG please help
Paul Hankin
paul.hankin at gmail.com
Wed Dec 26 07:02:01 EST 2007
More information about the Python-list mailing list
Wed Dec 26 07:02:01 EST 2007
- Previous message (by thread): OMG please help
- Next message (by thread): Converting old "shelve" databases to gdbm
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Dec 26, 1:09 am, Steven D'Aprano <st... at REMOVE-THIS- cybersource.com.au> wrote: > On Mon, 24 Dec 2007 17:14:58 +0100, Martin P. Hellwig wrote: > > As Dennis already pointed out I like to use dictionaries in these cases, > > so I would use sand = dict() instead of sands = list() and would do > > sand[i] = pygame.image.load(name) > > > Then you can retrieve the content by doing sand[your_number]. > > If the keys are just the integers 0...n inclusive, then why bother with > the extra overhead of a dict when you get all the functionality you need > from a list? The keys aren't integers 0...n here, they're 1, 2, 3, 4, L, R, T, D, TL, TR, BL, BR in the code, so a dict is preferable to a list. Incidentally Katie: is 'D' a typo? It should be 'B' for consistency. Also, functions can be passed arguments, and doing so is preferable to passing information via global variables. So def LoadMaterial(loader): ... sand = LoadMaterial('Sand') Is a lot better than def LoadMaterial(): ... code using 'loader' loader = 'Sand' sand = LoadMaterial()
- Previous message (by thread): OMG please help
- Next message (by thread): Converting old "shelve" databases to gdbm
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list