Re: Implement C's Switch in Python 3

2019-03-15 Thread jfong
Sayth Renshaw at 2019/2/3 UTC+8 AM9:52:50 wrote: > Or perhaps use a 3rd party library like > https://github.com/mikeckennedy/python-switch Thank you for this link. It's a good general implementation. --Jach -- https://mail.python.org/mailman/listinfo/python-list

Re: Implement C's Switch in Python 3 [OT languages]

2019-02-07 Thread Christian Gollwitzer
Am 05.02.19 um 02:20 schrieb DL Neil: So, even with the French making their dates into sentences, not a single one uses ordinals! - did the computer people in all these languages/cultures decide that the more numeric approach was better/easier/... (ie simpler/less-complex) :) For the two

Re: Implement C's Switch in Python 3

2019-02-05 Thread MRAB
On 2019-02-06 00:25, John Sanders wrote: On Saturday, February 2, 2019 at 6:47:49 PM UTC-6, Sayth Renshaw wrote: Hi I am trying to convert a switch statement from C into Python. (why? practising). This is the C code. printf("Dated this %d", day); switch (day) { case 1: case 21: case

Re: Implement C's Switch in Python 3

2019-02-05 Thread John Sanders
On Saturday, February 2, 2019 at 6:47:49 PM UTC-6, Sayth Renshaw wrote: > Hi > > I am trying to convert a switch statement from C into Python. (why? > practising). > > This is the C code. > > printf("Dated this %d", day); > switch (day) { > case 1: case 21: case 31: >

Re: Implement C's Switch in Python 3 [OT languages]

2019-02-04 Thread DL Neil
On 4/02/19 9:25 PM, Christian Gollwitzer wrote: Am 04.02.19 um 09:18 schrieb Christian Gollwitzer: I think English is quite "unique" with writing out the ending of the ordinals attached to arabic numerals. Of course, there is a Wikipedia page about it:

Re: Implement C's Switch in Python 3 [OT languages]

2019-02-04 Thread Christian Gollwitzer
Am 04.02.19 um 09:18 schrieb Christian Gollwitzer: I think English is quite "unique" with writing out the ending of the ordinals attached to arabic numerals. Of course, there is a Wikipedia page about it: https://en.wikipedia.org/wiki/Ordinal_indicator So I was wrong and the

Re: Implement C's Switch in Python 3 [OT languages]

2019-02-04 Thread Christian Gollwitzer
Am 04.02.19 um 04:11 schrieb DL Neil: > On 4/02/19 10:00 AM, Christian Gollwitzer wrote: Am 03.02.19 um 09:32 schrieb DL Neil: Now back to ordinal dates - the "st", "th", etc suffixes only work in English. You'd need another list (but no great coding complexity) to cope with a second, third,

Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil
Christian, On 4/02/19 10:00 AM, Christian Gollwitzer wrote: Am 03.02.19 um 09:32 schrieb DL Neil: Now back to ordinal dates - the "st", "th", etc suffixes only work in English. You'd need another list (but no great coding complexity) to cope with a second, third, ... language! Only for

Re: Implement C's Switch in Python 3

2019-02-03 Thread Chris Angelico
On Mon, Feb 4, 2019 at 10:53 AM Avi Gross wrote: > It is very bad form to have ambiguous compressed formats. Even if you include > a slash or minus sign or period or the delimiter of your choice, I sometimes > see this: > > 01/02/2020 > > And I wonder if it is meant to be January 2nd or

Re: Implement C's Switch in Python 3

2019-02-03 Thread Chris Angelico
On Mon, Feb 4, 2019 at 11:08 AM Chris Angelico wrote: > If you need to attach some *other* time zone (which should be rare - > ONLY do this if you absolutely cannot translate to UTC) BTW, there are some legit reasons for keeping something in a different timezone. If you're representing an

RE: Implement C's Switch in Python 3

2019-02-03 Thread Avi Gross
Comment at end: -Original Message- From: Python-list On Behalf Of Bob van der Poel Sent: Sunday, February 3, 2019 4:01 PM To: DL Neil Cc: Python Subject: Re: Implement C's Switch in Python 3 I'm surprised that no one has yet addressed the year 1 problem. Hopefully we're doing

Re: Implement C's Switch in Python 3

2019-02-03 Thread Bob van der Poel
On Sun, Feb 3, 2019 at 2:15 PM Chris Angelico wrote: > On Mon, Feb 4, 2019 at 8:02 AM Bob van der Poel wrote: > > > > I'm surprised that no one has yet addressed the year 1 problem. > Hopefully we're doing numeric, not alpha sorts on the stuff before the 1st > '-'. And, the compact versions

Re: Implement C's Switch in Python 3

2019-02-03 Thread Chris Angelico
On Mon, Feb 4, 2019 at 8:02 AM Bob van der Poel wrote: > > I'm surprised that no one has yet addressed the year 1 problem. Hopefully > we're doing numeric, not alpha sorts on the stuff before the 1st '-'. And, > the compact versions will really screw up :). > Compact versions? You mean

Re: Implement C's Switch in Python 3

2019-02-03 Thread Christian Gollwitzer
Am 03.02.19 um 09:32 schrieb DL Neil: Now back to ordinal dates - the "st", "th", etc suffixes only work in English. You'd need another list (but no great coding complexity) to cope with a second, third, ... language! Only for some languages. In other languages there can be, for example,

Re: Implement C's Switch in Python 3

2019-02-03 Thread Chris Angelico
On Mon, Feb 4, 2019 at 7:35 AM DL Neil wrote: > > On 3/02/19 10:16 PM, Chris Angelico wrote: > >> There's normal and there's normal - like it's tomato or tomato? > > I dunno. I'm the kind of normal that likes tomatoes (not to be > > confused with tomatoes). Does that help? > > If you like

Re: Implement C's Switch in Python 3

2019-02-03 Thread Bob van der Poel
On Sun, Feb 3, 2019 at 1:35 PM DL Neil wrote: > On 3/02/19 10:16 PM, Chris Angelico wrote: > > On Sun, Feb 3, 2019 at 8:09 PM DL Neil > wrote: > >> On 3/02/19 9:45 PM, Chris Angelico wrote: > >>> Which is why I always write dates in sorted format, usually eschewing > >>> delimiters: > >>> //CJA

Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil
On 3/02/19 10:16 PM, Chris Angelico wrote: On Sun, Feb 3, 2019 at 8:09 PM DL Neil wrote: On 3/02/19 9:45 PM, Chris Angelico wrote: Which is why I always write dates in sorted format, usually eschewing delimiters: //CJA 20160511: Is this still happening? I don't remember seeing it in three

RE: Implement C's Switch in Python 3

2019-02-03 Thread Avi Gross
The discussion strictly sets a limit of 31 for the largest number of days in a month and asks for suffixes used to make ordinal numbers like 31st. But in reality, you can go to 99th and beyond for other purposes albeit the pattern for making 101 and on seems to repeat. The last algorithm I wrote

Re: Implement C's Switch in Python 3

2019-02-03 Thread Frank Millman
"Sayth Renshaw" wrote in message news:73a1c64c-7fb1-4fc8-98a2-b6939e82a...@googlegroups.com... chooseFrom = { day : nthSuffix(day) for day in range(1,32)} chooseFrom {1: '1st', 2: '2nd', 3: '3rd', 4: '4th', 5: '5th', 6: '6th', 7: '7th', 8: '8th', 9: '9th', 10: '10th', 11: '11th', 12: '12th',

Re: Implement C's Switch in Python 3

2019-02-03 Thread Chris Angelico
On Sun, Feb 3, 2019 at 8:09 PM DL Neil wrote: > > On 3/02/19 9:45 PM, Chris Angelico wrote: > > Which is why I always write dates in sorted format, usually eschewing > > delimiters: > > > > //CJA 20160511: Is this still happening? I don't remember seeing it in > > three parts of forever. > > Sure

Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil
Chris, On 3/02/19 9:45 PM, Chris Angelico wrote: On Sun, Feb 3, 2019 at 7:40 PM DL Neil wrote: This would normally see us coding "2019-02-03". The arrangement of larger to ever more precise time-units is very useful in databases and applications such as file-names, because it sequences

Re: Implement C's Switch in Python 3

2019-02-03 Thread Chris Angelico
On Sun, Feb 3, 2019 at 7:40 PM DL Neil wrote: > This would normally see us coding "2019-02-03". The arrangement of > larger to ever more precise time-units is very useful in databases and > applications such as file-names, because it sequences logically. > > However, that is not the way 'normal

Re: Implement C's Switch in Python 3

2019-02-03 Thread DL Neil
When a client demanded his way on this issue, the action we took was, as below, to create a list (called ordinal) and to use the dd (day) value as an index. [ nthSuffix(day) for day in range(1,32)] ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th',

Re: Implement C's Switch in Python 3

2019-02-03 Thread Stefan Behnel
Chris Angelico schrieb am 03.02.19 um 02:23: > Of course, you can also precompute this: > > day_ordinal = mapper( > [1, 21, 31], "st", > [2, 22], "nd", > [3, 23], "rd", > ) > def f(x): return day_ordinal.get(x, "th") … in which case I would also 'precompute' the ".get"

Re: Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
21st', 22: '22nd', 23: '23rd', 24: '24th', 25: '25th', 26: '26th', 27: > '27th', 28: '28th', 29: '29th', 30: '30th', 31: '31st'} > >>> chooseFrom[1] > '1st' > >>> chooseFrom[11] > '11th' > >>> chooseFrom[21] > '21st' > > Subject: Re: Implement

RE: Implement C's Switch in Python 3

2019-02-02 Thread Avi Gross
21] '21st' -Original Message----- From: Python-list On Behalf Of MRAB Sent: Saturday, February 2, 2019 10:06 PM To: python-list@python.org Subject: Re: Implement C's Switch in Python 3 On 2019-02-03 02:51, Avi Gross wrote: > I may be missing something, but the focus seems to be only on the &

Re: Implement C's Switch in Python 3

2019-02-02 Thread Igor Korot
t; 14th > 15th > 16th > 17th > 18th > 19th > 20th > 21st > 22nd > 23rd > 24th > 25th > 26th > 27th > 28th > 29th > 30th > 31st > > -Original Message- > From: Python-list On > Behalf Of Sayth Renshaw > Sent: Saturday, February

Re: Implement C's Switch in Python 3

2019-02-02 Thread MRAB
On 2019-02-03 02:51, Avi Gross wrote: I may be missing something, but the focus seems to be only on the rightmost digit. You can get that with I had the same thought, but came across a problem. "11st", "12nd", "13rd"? [snip] Output: for day in range(1, 32): print( nthSuffix(day))

RE: Implement C's Switch in Python 3

2019-02-02 Thread Avi Gross
8th 19th 20th 21st 22nd 23rd 24th 25th 26th 27th 28th 29th 30th 31st -Original Message- From: Python-list On Behalf Of Sayth Renshaw Sent: Saturday, February 2, 2019 8:53 PM To: python-list@python.org Subject: Re: Implement C's Switch in Python 3 > >I am trying to convert a switch

Re: Implement C's Switch in Python 3

2019-02-02 Thread Skip Montanaro
Cameron wrote: > Skip has commented on lists being unhashable. We can elaborate on that > if you like. > > However, even if you went to tuples (which would let you construct the > dict you lay out above), there is another problem. > > You're looking up "x" in the dict. But the keys of the dict

Re: Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
> >I am trying to convert a switch statement from C into Python. (why? > >practising). > > > >This is the C code. > > > >printf("Dated this %d", day); > > switch (day) { > >case 1: case 21: case 31: > >printf("st"); break; > >case 2: case 22: > >printf("nd"); break; > >

Re: Implement C's Switch in Python 3

2019-02-02 Thread Cameron Simpson
On 02Feb2019 16:47, Sayth Renshaw wrote: I am trying to convert a switch statement from C into Python. (why? practising). This is the C code. printf("Dated this %d", day); switch (day) { case 1: case 21: case 31: printf("st"); break; case 2: case 22: printf("nd"); break;

Re: Implement C's Switch in Python 3

2019-02-02 Thread Chris Angelico
On Sun, Feb 3, 2019 at 11:51 AM Sayth Renshaw wrote: > > Hi > > I am trying to convert a switch statement from C into Python. (why? > practising). > > This is the C code. > > printf("Dated this %d", day); > switch (day) { > case 1: case 21: case 31: > printf("st"); break; >

Re: Implement C's Switch in Python 3

2019-02-02 Thread Skip Montanaro
> > I have an unhashable type list. > Try replacing the list with a tuple. Also, read up on immutable v mutable types and dictionary keys for a bit of background on why a list won't work. Skip > -- https://mail.python.org/mailman/listinfo/python-list

Implement C's Switch in Python 3

2019-02-02 Thread Sayth Renshaw
Hi I am trying to convert a switch statement from C into Python. (why? practising). This is the C code. printf("Dated this %d", day); switch (day) { case 1: case 21: case 31: printf("st"); break; case 2: case 22: printf("nd"); break; case 3: case 23: