[Edu-sig] Python First: Free access for educators

Anna Ravenscroft annaraven at gmail.com
Wed Mar 8 20:18:09 CET 2006


On 3/8/06, w chun <wescpy at gmail.com> wrote:
>
> > def switch(choice, functions = [cf0, cf1, cf2, cf3])
>
>
> should we really be showing folks using a mutable object as a default
> argument? ;-)
>
> i'd suggest: (1) changing it to a tuple, or (2) None and figure it out
> after that.


I prefer dicts for this sort of thing. That way "choice" could be something
meaningful. For example, I recently wrote a python script showing how
different sorting algorithms work (for my discrete math class). I have a
dict of algorithms, something like (I'm typing from memory before my first
cup of coffee - go gentle on me):

algs = {'quick':quicksort, 'merge':mergesort, "insert": insertionsort}
choice = "quick" # however we get the choice..eg from the command line.
if choice in algs:
    choice(datatosort)
...

I really like not having to remember order. This way, I get the right
function easily. And I can print out the list of keys to remind me which
functions are available.

Anna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/edu-sig/attachments/20060308/3801bc14/attachment.html 


More information about the Edu-sig mailing list