Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60629 > unrolled thread

Re: python for everyday tasks

Started byJean-Michel Pichavant <jeanmichel@sequans.com>
First post2013-11-27 19:16 +0100
Last post2013-11-27 19:16 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Re: python for everyday tasks Jean-Michel Pichavant <jeanmichel@sequans.com> - 2013-11-27 19:16 +0100

#60629 — Re: python for everyday tasks

FromJean-Michel Pichavant <jeanmichel@sequans.com>
Date2013-11-27 19:16 +0100
SubjectRe: python for everyday tasks
Message-ID<mailman.3314.1385576168.18130.python-list@python.org>
----- 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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web