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('
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
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: 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
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
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
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
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
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
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
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
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),
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
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.
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
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
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
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
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 :)
> 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
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
21 matches
Mail list logo