czwartek, 12 czerwca 2008

Switch-case emulation in Python

There is no switch-case construction in python. Although one can emulate its simplicity and compactness with appropriate use of a dictionary.

d = {}
d['condition1'] = 'result1'
d['condition2'] = 'result2'
d['condition3'] = 'result3'
result = d[condition]

Result can be execution of appropriate function.

0 komentarze: