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)
Aahz, 12.05.2010 17:33:
Stefan Behnel wrote:
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In article,
Terry Reedy wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote:
Have I missed something, or wouldn't this work just as well:
list_of_str
In article ,
Stefan Behnel wrote:
>superpollo, 11.05.2010 17:03:
>> Aahz ha scritto:
>>> In article ,
>>> Terry Reedy wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
> On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote:
>> Have I missed something, or wouldn't this work just as well:
>
Stefan Behnel ha scritto:
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In article ,
Terry Reedy wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho
wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes',
superpollo, 11.05.2010 17:03:
Aahz ha scritto:
In article ,
Terry Reedy wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote:
Have I missed something, or wouldn't this work just as well:
list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas
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] ==
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 er
In article ,
Terry Reedy 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 added enough to
>more than balance the slight expansion of the l
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 slic
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 met
James Mills ha scritto:
On Wed, May 12, 2010 at 2:01 AM, wrote:
word[len(word)-1:]
This works just as well:
word[-1:]
d'uh. ;-)
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, May 12, 2010 at 2:01 AM, wrote:
>> word[len(word)-1:]
This works just as well:
>>> word[-1:]
cheers
James
--
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
Superpollo,
> word[len(word)-1:]
Perfect! Thank you,
Malcolm
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, May 11, 2010 at 10:37 AM, 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 sequence instead of the
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 ex
Aahz ha scritto:
In article ,
Terry Reedy wrote:
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho 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_
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?
In article ,
Terry Reedy wrote:
>On 5/10/2010 5:35 AM, James Mills wrote:
>> On Mon, May 10, 2010 at 6:50 PM, Xavier Ho 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_o
On Mon, May 10, 2010 at 10:23 PM, Terry Reedy wrote:
> On 5/10/2010 5:35 AM, James Mills wrote:
>>
>> On Mon, May 10, 2010 at 6:50 PM, Xavier Ho wrote:
>>>
>>> Have I missed something, or wouldn't this work just as well:
>>>
>> list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
>>>
On 5/10/2010 5:35 AM, James Mills wrote:
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho 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 wo
In article ,
James Mills wrote:
>On Mon, May 10, 2010 at 6:50 PM, Xavier Ho 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
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
On Mon, May 10, 2010 at 6:50 PM, Xavier Ho 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 completeness (ju
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
look
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 wrote:
> Hello
>
> I am trying to find
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 func
27 matches
Mail list logo