Constructor problem
Alex Martelli
aleaxit at yahoo.com
Thu Oct 28 19:04:03 EDT 2004
More information about the Python-list mailing list
Thu Oct 28 19:04:03 EDT 2004
- Previous message (by thread): Constructor problem
- Next message (by thread): ANN: Snakelets 1.37 (simple-to-use web app server with dynamic pages)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Nick <mediocre_person at hotmail.com> wrote: ... > I'm writing a simple class to represent a deck of cards. Here is the > stripped down version. Notice classes Deck and Deck2. Class Deck works, > Deck2 does not. My thinking is that it should be more efficient (a la > Deck2) to pre-create the list, and then modify it, rather than appending > Cards as in Deck. Everybody's accusing you of premature optimization, and they have a point, but, there IS a very simple approach that's fast and useful (particularly in Python 2.4 -- if you're interested in performance, get and use 2.4 beta 1 *NOW*!!!-): a list comprehension: self.deck = [Card(r, s) for r in xrange(13) for s in xrange(4)] Alex
- Previous message (by thread): Constructor problem
- Next message (by thread): ANN: Snakelets 1.37 (simple-to-use web app server with dynamic pages)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list