[Tutor] split on tab and new line

R. Alan Monroe amonroe at columbus.rr.com
Sat Sep 4 18:02:54 CEST 2004


> One subproblem might be something to take a "label" ("A"), and translate
> that into some value ("Apple").  In fact, we can hardcode something right
> now:

> ###
> def getLabelName(label):
>     if label == 'A': return 'Apple'
>     if label == 'B': return 'Boy'
>     return 'I-Dont-Know-Yet'
> ###

Rather than an if-tree, you could try a dictionary here...

allmylabels = { 'A': 'Apple',
                'B': 'Boy' }


                
Alan



More information about the Tutor mailing list