python for everyday tasks

Jean-Michel Pichavant jeanmichel at
Wed Nov 27 19:16:06 CET 2013

----- Original Message -----
> On Saturday 23 November 2013 02:01:26 Steven D'Aprano wrote:
> > * Python is not Java, and Java is not Python either:
> > 
> >
> >
> Thanks for all those references.
> There's this statement in the first article:
> "Got a switch statement? The Python translation is a hash table, not
> a bunch
> of if-then statments. Got a bunch of if-then's that wouldn't be a
> switch
> statement in Java because strings are involved? It's still a hash
> table. "
> I can't figure out how would you translate a switch statement into
> hash table
> in general case.
> --

It actually refers to python dictionaries, they use hash-able object as keys:

switch (foo):
  1: do_something()
  2: do_someotherthing()

can be written in python that way:

  1: do_something,
  2: do_someotherthing,

There are some limitation though, without going into details.



The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

More information about the Python-list mailing list