Re: Switch function

2019-02-03 Thread Dan Sommers
On 2/3/19 9:03 PM, Avi Gross wrote: > The example I show above could in many cases be done as you describe > but what are you gaining? > > I mean if I subtract the integer representation of a keyboard > alphabetic letter (ASCII for the example) from letter 'a' or 'A' then > A maps to 0 and B maps

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 some

RE: Switch function

2019-02-03 Thread Avi Gross
Dan, I agree and have felt no need to do a method like this. Most of the time a switch is easy to avoid or even forget that it exists. I rarely needed to use these years ago when they were available in C and C++ , JAVA, JavaScript, PERL or R or under other *names* but similar functionality like

Re: Switch function

2019-02-03 Thread Dan Sommers
On 2/3/19 5:40 PM, Avi Gross wrote: Bottom line, does anyone bother using anything like this? It is actually a bunch of hidden IF statements matched in order but may meet many needs. I sure don't. In the rare case that I might use a switch statement in another language, I just use a series of

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 February

Ordered Ordinal number methods

2019-02-03 Thread Avi Gross
[NOTE: message is a tad long as it discusses multiple possible solutions and concerns including code.] The original question was how to do some reasonable translation from something like the "switch" statement in languages that have it, including C and R. Other languages use their own variants

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 instant

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 nu

Switch function

2019-02-03 Thread Avi Gross
Message asking about a fairly simple way to implement a switch in python as per the ongoing discussion. I wrote a function that might emulate a fairly simple general use of switch. A function would take N+2 arguments of the form: 1: something to switch based on 2,3: something to match to

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 non-

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, case

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 tomatoes

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 part

Re: mask and proper index

2019-02-03 Thread Peter Otten
diego.aves...@gmail.com wrote: > Dear all, > > I am trying to apply a mask to my dataframe: > > mask = (df['datatime'] > start_date) & (df['datatime'] <= end_date) > df = df.loc[mask] > > > It seems to work pretty well. > > After that I crate the cumulative of its element as: > > > PP_cumPP

mask and proper index

2019-02-03 Thread diego . avesani
Dear all, I am trying to apply a mask to my dataframe: mask = (df['datatime'] > start_date) & (df['datatime'] <= end_date) df = df.loc[mask] It seems to work pretty well. After that I crate the cumulative of its element as: PP_cumPP = np.cumsum(df[PP_station]) However, I am not able to co

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 logical

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 pe

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', '13th'

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" and