Terry Reedy wrote:
Thank you for that timing report.
Enjoyed doing it, and more on that below.
My main point is that there are two ways to fetch a char, the difference
being the error return -- exception IndexError versus error value ''.
This is an example of out-of-band versus in-band
Bryan, 12.05.2010 08:55:
Now back to the arguably-interesting issue of speed in the particular
problem here: 'Superpollo' had suggested another variant, which I
appended to my timeit targets, resulting in:
[s for s in strs if s.startswith('a')] took: 5.68393977159
[s for s in strs if s[:1] ==
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In article mailman.11.1273548189.32709.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Hocont...@xavierho.com wrote:
Have I missed something, or
Stefan Behnel ha scritto:
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In article mailman.11.1273548189.32709.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Hocont...@xavierho.com
wrote:
Have I
In article mailman.100.1273653829.32709.python-l...@python.org,
Stefan Behnel stefan...@behnel.de wrote:
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In article mailman.11.1273548189.32709.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
Aahz, 12.05.2010 17:33:
Stefan Behnelstefan...@behnel.de wrote:
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In articlemailman.11.1273548189.32709.python-l...@python.org,
Terry Reedytjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier
On 5/12/2010 11:33 AM, Aahz wrote:
also, what if the OP intended words that begin with x with x a string
(as opposed to a single character) ?
word[:len(x)] == x
will work in that case.
But that's now going to be slower. ;-) (Unless one makes the obvious
optimization to hoist len(x)
In article mailman.11.1273548189.32709.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Hocont...@xavierho.com wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings =
Terry,
... word[0:1] does the same thing. All Python programmers should learn to
use slicing to extract a char from a string that might be empty.
Is there an equivalent way to slice the last char from a string (similar
to an .endswith) that doesn't raise an exception when a string is empty?
Aahz ha scritto:
In article mailman.11.1273548189.32709.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Hocont...@xavierho.com wrote:
Have I missed something, or wouldn't this work just as well:
pyt...@bdurham.com ha scritto:
Terry,
... word[0:1] does the same thing. All Python programmers should learn to use
slicing to extract a char from a string that might be empty.
Is there an equivalent way to slice the last char from a string (similar
to an .endswith) that doesn't raise an
On Tue, May 11, 2010 at 10:37 AM, pyt...@bdurham.com wrote:
Is there an equivalent way to slice the last char from a string (similar
to an .endswith) that doesn't raise an exception when a string is empty?
If you use negative indexes in the slice, they refer to items from the
end of the
Superpollo,
word[len(word)-1:]
Perfect! Thank you,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
Jerry,
If you use negative indexes in the slice, they refer to items from the end of
the sequence instead of the front. So slicing the last character from the
string would be:
word[-1:]
Perfect! Thank you,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, May 12, 2010 at 2:01 AM, pyt...@bdurham.com wrote:
word[len(word)-1:]
This works just as well:
word[-1:]
cheers
James
--
http://mail.python.org/mailman/listinfo/python-list
James Mills ha scritto:
On Wed, May 12, 2010 at 2:01 AM, pyt...@bdurham.com wrote:
word[len(word)-1:]
This works just as well:
word[-1:]
d'uh. ;-)
--
http://mail.python.org/mailman/listinfo/python-list
Tycho Andersen wrote:
Terry Reedy wrote:
... word[0:1] does the same thing. All Python programmers should learn to
use slicing to extract a char from a string that might be empty.
The method call of .startswith() will be slower, I am sure.
Why? Isn't slicing just sugar for a method
On 5/11/2010 6:01 PM, Bryan wrote:
Tycho Andersen wrote:
Terry Reedy wrote:
... word[0:1] does the same thing. All Python programmers should learn to
use slicing to extract a char from a string that might be empty.
The method call of .startswith() will be slower, I am sure.
Why? Isn't
In article mailman.84.1273630878.32709.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
.startswith and .endswith are methods that wrap the special cases of
slice at an end and compare to one value. There are not necessary, and
save no keystrokes, but Guido obviously thought they
Hello
I am trying to find if there is a string OR list function that will
search a list of strings for all the strings that start with 'a'
return a new list containing all the strings that started with 'a'.
I have had a search of Python site I could not find what I am
looking for, does a
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']
['awes', 'asdgas']
Cheers,
Xav
On Mon, May 10, 2010 at 6:40 PM, Jimbo nill...@yahoo.com wrote:
Hello
I am trying
Jimbo ha scritto:
Hello
I am trying to find if there is a string OR list function that will
search a list of strings for all the strings that start with 'a'
return a new list containing all the strings that started with 'a'.
I have had a search of Python site I could not find what I am
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho cont...@xavierho.com wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']
['awes', 'asdgas']
I would do this for
superpollo ha scritto:
Jimbo ha scritto:
Hello
I am trying to find if there is a string OR list function that will
search a list of strings for all the strings that start with 'a'
return a new list containing all the strings that started with 'a'.
I have had a search of Python site I could
In article mailman.2840.1273484131.23598.python-l...@python.org,
James Mills prolo...@shortcircuit.net.au wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho cont...@xavierho.com wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes', '3465sdg',
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Hocont...@xavierho.com wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
[word for word in list_of_strings if word[0] == 'a']
On Mon, May 10, 2010 at 10:23 PM, Terry Reedy tjre...@udel.edu wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Hocont...@xavierho.com wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes', '3465sdg',
27 matches
Mail list logo