On Friday, Apr 15, 2005, at 14:31 America/Chicago, [EMAIL PROTECTED] wrote:
So I'm sure that's probably way too much information for most of you!! But my remaining questions are these:
1. what is/where can i get the "pickle" module for storing/saving changes to the high score list? 2. tabs/aligning the score in a column when i display it
The Python Cookbook is a good place to look to see if someone has already provided a recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/
There are 2 table indenters at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/267662
In my previous post there is a suggestion on using the longest number to print all teh numbers in a space that big. (There was also an error in my understanding of your program where you checked the user's score against the *lowest* score in the list, not the highest--sorry about that!)
You can think of the "key" option like this: when sort comes to compare elements x and y it gives you the option of telling *what* you want to compare about x and y. You might, for example, want to sort a list of strings based on their *length* not on their alphabetical position. To do so, write a 1-argument function that returns the length of a string:3. displaying the score/scorelist stuff on the graphics window instead of the python window 4. key=lambda x: x[1] ?
###
Python 2.4 (#1, Apr 4 2005, 13:57:19)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> l=['sea', 'd', 'bee']
>>> l.sort() #the normal sort
>>> l
['bee', 'd', 'sea']
>>> def strlen(x): # the 1-argument function
... return len(x)
...
>>> l.sort(key=strlen)
>>> l
['d', 'sea', 'bee'] #the length sort; it's stable so sea is still before bee
>>> def length_alph(x): #'key' function if you want length first and then alphabetical
... return (len(x),x)
...
>>> l.sort(key=length_alph); l
['d', 'bee', 'sea']
###
This list is a great place for learning. It's one of the things that has made working with Python so enjoyable and productive. (Thanks to all!)Thank you so much for all of your suggestions! I can't wait until I learn enough python to be able to give some help back :)
/c
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor