python for everyday tasks

Jean-Michel Pichavant jeanmichel at sequans.com
Wed Nov 27 13:16:06 EST 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:
> > 
> > http://dirtsimple.org/2004/12/python-is-not-java.html
> > http://dirtsimple.org/2004/12/java-is-not-python-either.html
> 
> 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.
> --
> https://mail.python.org/mailman/listinfo/python-list
> 

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,
}[foo]()

There are some limitation though, without going into details.

JM


-- IMPORTANT NOTICE: 

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