[Tutor] Equivalent 'case' statement

inhahe inhahe at gmail.com
Fri May 23 01:25:55 CEST 2008


>
> cases = {
> 1: lambda: x*2
> 2: lambda: y**2
> 3: lambda: sys.stdout.write("hi\n")
> }
>

i forgot the commas.

 cases = {
 1: lambda: x*2,
 2: lambda: y**2,
 3: lambda: sys.stdout.write("hi\n")
 }


>
> your functions and lambdas can also take parameters of course
>

lambda a, b: a*b


More information about the Tutor mailing list