# Fwd: [Tutor] high score lists

D. Hartley denise.hartley at gmail.com
Sat Apr 16 01:46:30 CEST 2005

```Thanks for the extra info on the lambda function.  That clears it out
a lot! I'll be sure to save that.

Re: "....The "rjust" string method is what you're looking for, methinks.

required.  That would right-align my right column, then? That would
look nice.  But where would you put it to make the other column line
up? I wish 'help' gave examples!

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!

> That's heavily dependent on what you're using. Pygame? Tkinter?
> Something else?

I'm using the pygame module, yep. begin_graphics( ), end_graphics( ),
etc.  Any ideas?

Thanks again!
~Denise

---------- Forwarded message ----------
From: Max Noel <maxnoel_fr at yahoo.fr>
Date: Apr 15, 2005 4:12 PM
Subject: Re: [Tutor] high score lists
To: "D. Hartley" <denise.hartley at gmail.com>
Cc: Python tutor <tutor at python.org>

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, 8, 10, 12, 14, 16, 18]

The first and second lines should be obvious ;) . Now, on line 3, I
use two things:
1) The "map" function. It takes 2 arguments: a function and an iterable
(a list, here). It then applies the function to each member of the
list, and returns the result.
2) A lambda function. "lambda x: 2*x" is a function that takes 1
argument, x, and returns 2*x. You see, I couldn't be bothered with
def'ing such a trivial function earlier in the program. I could have

>>> def twice(x):
>>>     return 2*x
>>> a = range(10)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> map(twice, a)
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]

And the result would have been the same. So a lambda function is just
a 1-line function you only want to use as an argument to another
function (functions are objects) and can't be bothered with/don't want
to def elsewhere in the program. That's all.

> Does anyone know?  Also how to make the scores
> line up in a column (and not just a fixed amount of space, either
> through tabs or hard-coding)?

The "rjust" string method is what you're looking for, methinks.

> 1. what is/where can i get the "pickle" module for storing/saving
> changes to the high score list?

pickle is part of the standard Python distribution. import pickle is
all you need to do.

> 3. displaying the score/scorelist stuff on the graphics window instead
> of the python window

That's heavily dependent on what you're using. Pygame? Tkinter?
Something else?

> 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 :)

That moment will come sooner than you think. Python is remarkably easy
to learn, especially with the help of this mailing list. It's amazing
the insight you gain by trying to help others.
I've been using Python for about 6 months now, and it definitely is my
favorite language. I can't wait to do some serious programming in it
(don't have enough time at the moment, with all the work I have to do
in Java... But as soon as Shadowrun 4 hits the stores, I'll start
working on a character generator, perhaps learning PyObjC in the
process).

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge a
perfect, immortal machine?"
```