sequence[i:j:k]
syntax in a post here. When did this happen?
(I'm just curious whether it existed in 1.5.x or not.
If so I'm stupid - otoh if it was introduced in 2.x
I'm just slow...)
Well, I got some good news and some bad news. According to the docs,
it existed in 1.4 but the built-in sequences didn't support it until
2.3. It's not used that often anyway so you haven't been missing much.
http://www.python.org/doc/2.3.5/whatsnew/section-slices.html
Googling for 'python extended slice' returns this as the first hit:
http://www.python.org/doc/2.3.5/whatsnew/section-slices.html
> 15 Extended Slices
>
> Ever since Python 1.4, the slicing syntax has supported an optional
> third ``step'' or ``stride'' argument. For example, these are all
> legal Python syntax: L[1:10:2], L[:-1:1], L[::-1]. This was added to
> Python at the request of the developers of Numerical Python, which
> uses the third argument extensively. However, Python's built-in list,
> tuple, and string sequence types have never supported this feature,
> raising a TypeError if you tried it. Michael Hudson contributed a
> patch to fix this shortcoming.
So extended slices have existed since Python 1.4, but builtin types only
started to support them from 2.3.
Fine (I knew they existed in Numerical Python way back when...)
> On Thu, Aug 20, 2009 at 2:13 PM, David C Ullrich<dull...@sprynet.com>
> wrote:
>> I just noticed that
>>
>> sequence[i:j:k]
>>
>> syntax in a post here. When did this happen?
>>
>> (I'm just curious whether it existed in 1.5.x or not. If so I'm stupid
>> - otoh if it was introduced in 2.x I'm just slow...)
>>
>>
> Well, I got some good news and some bad news. According to the docs, it
> existed in 1.4 but the built-in sequences didn't support it until 2.3.
> It's not used that often anyway so you haven't been missing much.
So I'm slow, fine. (There were several times when I was using 1.5.3
and wished they were there - transposing matrices, etc.)
>
> http://www.python.org/doc/2.3.5/whatsnew/section-slices.html
Except that it's canonical for one specific operation:
'reverseme'[::-1]
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
"Given that C++ has pointers and typecasts, it's really hard to have a
serious conversation about type safety with a C++ programmer and keep a
straight face. It's kind of like having a guy who juggles chainsaws
wearing body armor arguing with a guy who juggles rubber chickens wearing
a T-shirt about who's in more danger." --Roy Smith
> So I'm slow, fine. (There were several times when I was using 1.5.3
> and wished they were there - transposing matrices, etc.)
1.5.THREE ??
Not sure. 1.SOMETHING. Sorry about the CONFUSION...
> In article <mailman.143.1250793...@python.org>,
> Benjamin Kaplan <benjami...@case.edu> wrote:
>>On Thu, Aug 20, 2009 at 2:13 PM, David C Ullrich<dull...@sprynet.com>
>>wrot= e:
>>>
>>> I just noticed that
>>> sequence[i:j:k]
>>
>>Well, I got some good news and some bad news. According to the docs, it
>>existed in 1.4 but the built-in sequences didn't support it until 2.3.
>>It's not used that often anyway so you haven't been missing much.
>
> Except that it's canonical for one specific operation:
>
> 'reverseme'[::-1]
It's like you guys are a bunch of programmers or something:
from math import sqrt
def Primes(n):
"""Return a list of the primes < n"""
sieve = range(n)
for k in range(2,int(sqrt(n))+2):
sieve[::k] = [1]*((n+k-1)/k)
return [p for p in sieve if p > 1]
Oops. Should have tested that a little more carefully
before posting. No time to fix it right now, customer just
got here. Let's just say we're looking for the primes
between sqrt(n) and n...
>[...]
>
>Oops. Should have tested that a little more carefully
>before posting. No time to fix it right now, customer just
>got here. Let's just say we're looking for the primes
>between sqrt(n) and n...
from math import sqrt
def Primes(n):
"""Return a list of the primes < n"""
sieve = range(n)
for k in range(2,int(sqrt(n))+2):
sieve[2*k::k] = [1]*((n-k-1)/k)
return [p for p in sieve if p > 1]
David C. Ullrich
"Understanding Godel isn't about following his formal proof.
That would make a mockery of everything Godel was up to."
(John Jones, "My talk about Godel to the post-grads."
in sci.logic.)