Re: [Tutor] high score lists

2005-04-16 Thread Kent Johnson
Chris Smith wrote: high = [(1000,"Denise"), (945,"Denise"), (883,"Denise"), (823,"Grant"), (779,"Aaron"), (702,"Pete"), (555,"Tom"), (443,"Tom"), (442,"Robin"), (404,"Pete")] for score, who in high: col1 = str(score).rjust(10) col2 = who.rjust(20).replace('

Re: [Tutor] high score lists

2005-04-15 Thread Chris Smith
On Friday, Apr 15, 2005, at 18:46 America/Chicago, [EMAIL PROTECTED] wrote: I did look at your example about using the longest number, but I couldnt really understand all of the code, and ended up deciding to arrange it so that the two columns were left-aligned: it looked like it would align them

Re: [Tutor] high score lists

2005-04-15 Thread Chris Smith
On Friday, Apr 15, 2005, at 20:40 America/Chicago, Jacob S. - [EMAIL PROTECTED] wrote: Great. len is a function though. Why use a second layer of function when len is a function in itself? l = ['d','sea','bee'] l.sort(key=len) l ['d', 'bee', 'sea'] LOL :-) Oooh, that's nice! OK, instead of w

Re: [Tutor] high score lists

2005-04-15 Thread Jacob S.
Re: pickle: Tried to look into how to use this - looks like it involves opening/closing files...? and dumping? and usr bins? ha ha. LOST. This might have to be another thread! Pickle is simple enough. # import pickle filename = "myfile.txt"## Change this with an appropriate fi

Re: [Tutor] high score lists

2005-04-15 Thread Jacob S.
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, wri

Re: [Tutor] high score lists

2005-04-15 Thread Kent Johnson
D. Hartley wrote: Re: the key discussion: that was very helpful, thank you! So if I had a list of tuples, and I wanted to use the "key" function to arrange the list of tuples by the second tuple item, I would define a function that returns the second tuple item, and then do key=find_second()? or co

Fwd: [Tutor] high score lists

2005-04-15 Thread D. Hartley
again! ~Denise -- Forwarded message -- From: Max Noel <[EMAIL PROTECTED]> Date: Apr 15, 2005 4:12 PM Subject: Re: [Tutor] high score lists To: "D. Hartley" <[EMAIL PROTECTED]> Cc: Python tutor On Apr 15, 2005, at 21:30, D. Hartley wrote: > Unless

Re: [Tutor] high score lists

2005-04-15 Thread Max Noel
On Apr 15, 2005, at 21:30, D. Hartley wrote: Unless you can explain what "lambda x: x[1]" does, in preschool-speak ;) That's an anonymous function, also known as a lambda function. Let's take an example: >>> a = range(10) >>> a [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> map(lambda x: 2*x, a) [0, 2, 4, 6

[Tutor] high score lists

2005-04-15 Thread D. Hartley
Thanks, I'll look at the cookbook! I didnt know it was available online. I did look at your example about using the longest number, but I couldnt really understand all of the code, and ended up deciding to arrange it so that the two columns were left-aligned: it looked like it would align them dow

Re: [Tutor] high score lists

2005-04-15 Thread Chris Smith
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/aligni

Re: [Tutor] high score lists

2005-04-15 Thread D. Hartley
Hello, everyone! Thank you for your very helpful comments. A few follow up questions, and then I'll show you where I've come so far: 1. Max - I think you're right about keeping it (score, name). It *is* much simpler to work with it that way, and would be easier to change the display and just ha

Re: [Tutor] high score lists

2005-04-15 Thread Max Noel
On Apr 15, 2005, at 03:32, [EMAIL PROTECTED] wrote: Interestingly, the key argument is the solution to this problem: arr = zip(range(10), range(10,0,-1)) arr [(0, 10), (1, 9), (2, 8), (3, 7), (4, 6), (5, 5), (6, 4), (7, 3), (8, 2), (9, 1)] arr.sort(key=lambda x: x[1]) arr [(9, 1), (8, 2), (7, 3),

Re: [Tutor] high score lists

2005-04-14 Thread Chris Smith
On Thursday, Apr 14, 2005, I wrote: which gives 200 Nina 20 Ben 2 Raj oops, copy and paste error...should be: 200 Nina 20 Ben 2 Raj ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] high score lists

2005-04-14 Thread Chris Smith
On Thursday, Apr 14, 2005, D. Hartley wrote: and a question about sorting (either way): I am trying it out with a list of tuples right now. The first problem I ran into is that when i sort it (scorelist.sort(reverse=True)), it sorts by the person's name (the first entry), and not by the score.

Re: [Tutor] high score lists

2005-04-14 Thread jfouhy
Quoting Max Noel <[EMAIL PROTECTED]>: > On Apr 15, 2005, at 01:33, D. Hartley wrote: > > (I also > > just ended up writing the list like [score,user] because I couldnt > > figure out how to get it to sort by the second half of the tuple. I > > need a better tutorial book, I think!) > I'm sti

Re: [Tutor] high score lists

2005-04-14 Thread Max Noel
On Apr 15, 2005, at 01:33, D. Hartley wrote: This is what I have so far: high_scorelist = [(1000,"Denise"), (945,"Denise"), (883,"Denise"), (823,"Grant"), (779,"Aaron"), (702,"Pete"), (555,"Tom"), (443,"Tom"), (442,"Robin"), (404,"Pete")] userscore = (441,"Joe") de

[Tutor] high score lists

2005-04-14 Thread D. Hartley
t; > > > > Hi > > > > I've read somewhere that the appropiate way to make a best score list is > > with a dictionarie > > > > So you'll have something like this: > > > > best_score={"Peter":100,"Jhon":23} > > > > Bes

Re: [Tutor] high score lists

2005-04-14 Thread Alberto Troiano
Hi I've read somewhere that the appropiate way to make a best score list is with a dictionarie So you'll have something like this: best_score={"Peter":100,"Jhon":23} Best Regards Alberto  Gaucho>From: Kent Johnson <[EMAIL PROTECTED]> >CC: Python tutor &g

Re: [Tutor] high score lists

2005-04-14 Thread Kent Johnson
R. Alan Monroe wrote: Anyone have some good beginning ideas/references to creating a high score list and storing scores in a simple python game? (if there's something in the pygames module, or a simpler python way). I'm mod'ing a space invaders-type game and would like to add a high score list :)

Re: [Tutor] high score lists

2005-04-14 Thread R. Alan Monroe
> Anyone have some good beginning ideas/references to creating a high > score list and storing scores in a simple python game? (if there's > something in the pygames module, or a simpler python way). I'm > mod'ing a space invaders-type game and would like to add a high score > list :) Quick and d

[Tutor] high score lists

2005-04-14 Thread D. Hartley
Anyone have some good beginning ideas/references to creating a high score list and storing scores in a simple python game? (if there's something in the pygames module, or a simpler python way). I'm mod'ing a space invaders-type game and would like to add a high score list :) Thanks! ~Denise