in reply to [OT] Python to Perl.
I don't know how to do this seemingly simple task in Python without an executable loop.
If you figure out a way to do this, please let me know.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [OT] Python to Perl.
by BrowserUk (Patriarch) on Jun 15, 2018 at 16:10 UTC | |
Actually yes. (Or whatever differences tehre are do not matter to the code I am converting as it now works.) It was another part of the code that was at fault; a range( 1 .. k ) that I had converted to 1 .. $k instead of 1..$k-1. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
| [reply] |
by davido (Cardinal) on Jun 15, 2018 at 17:02 UTC | |
Ah, this makes sense at some wacky level. Consider this array (language doesn't matter here, so this is pseudo-code):
Some languages use a convention where begin(array) is equivalent to array[0], and end(array) is equivalent to array[5], or one past the last element. A loop in such a world might be written like this:
The notation used for such a concept is sometimes this:
...meaning (0 <= x < 5). This concept and notation is common in C++. And is used by Python's range() function. Python's range method has the following semantics:
In each case start is inclusive, and stop is exclusive. [start,stop) in mathematical notation, or this: (start <= x < stop). Dave | [reply] [d/l] [select] |
by BrowserUk (Patriarch) on Jun 15, 2018 at 18:47 UTC | |
It's a perfectly rational choice, you just have to know it. However, the weird thing with this particular conversion is that I originally converted for j in range(a[t - p] + 1, k): to for my $j ( $a[ $t - $p ] + 1 .. $k-1 ) { but the code didn't work and I had to switch it to for my $j ( $a[ $t - $p ] + 1 .. $k ) { to make it work. Here's my conversion:
I omitted the feature where the first parameter is inspected for being an integer and alphabet 0 .. k-1 is generated internally because it make using a none zero-based, or non-sequential integers alphabet impossible. Ie. supply k as '3579' and instead of being taken as an alphabet of 4 characters, it gets converted to a 3k letter alphabet and blows your memory. Besides, it's far simpler to create an sequence externally and pass it in. And I've made no attempt to optimise it, because now I have a working Perl version for comparison, I'll code a fast version in either Julia or C. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice.
Suck that fhit
| [reply] [d/l] [select] |
by AnomalousMonk (Archbishop) on Jun 15, 2018 at 18:01 UTC | |
... this makes sense at some wacky level. For me, the semantic sense is that in a 0-based array, the length of the array can be used to represent its highest index. A D example: Output: (The expression ra[ 0 .. $ ] is shorthand for ra[ 0 .. ra.length ]) Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] |
by LanX (Saint) on Jun 16, 2018 at 23:15 UTC | |
[0..9[ = [0..3[ + [3..6[ + [6..9[ (pseudocode!) This "scales" well (in a mathematical sense) without needing to add or subtract at the edges, hence less error prone.
Cheers Rolf
| [reply] [d/l] |