On Mon, 28 Dec 2009 17:35:22 -0800, Aahz wrote:
> In article , Ed
> Keith wrote:
>>
>>I have a list call it 'l':
>>
>>l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>>
>>Notice that some of the items in the list start and end with an '*'. I
>>wish to construct a new list, call
In article ,
Ed Keith wrote:
>
>I have a list call it 'l':
>
>l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>
>Notice that some of the items in the list start and end with an '*'. I
>wish to construct a new list, call it 'n' which is all the members of l
>that start and end wit
On 2009-12-11, Grant Edwards wrote:
> On 2009-12-11, Neil Cerutti wrote:
>> On 2009-12-11, Grant Edwards wrote:
>>> [s[1:-1] for s in l if (s[0] == s[-1] == '*')]
>>
>> That last bit doesn't work right, does it, since an == expression
>> evaluates to True or False, no the true or false value its
On Fri, 11 Dec 2009 12:49:42 -0800, Ed Keith wrote:
> the following works:
>
> r = re.compile('\*(.+)\*')
>
> def f(s):
> m = r.match(s)
> if m:
> return m.group(1)
> else:
> return ''
>
> n = [f(x) for x in l if r.match(x)]
>
>
>
> But it is inefficient, b
On 12/12/2009 8:24 AM, Peter Otten wrote:
But it is inefficient, because it is matching the regex twice for each
item, and it is a bit ugly.
I could use:
n = []
for x in keys:
m = r.match(x)
if m:
n.append(m.group(1))
It is more efficient, but much uglier.
It's
import re
r = re.compile('\*(.+)\*')
def f(s):
m = r.match(s)
if m:
return m.group(1)
l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
n = [y for y in (f(x) for x in l) if y]
--
http://mail.python.org/mailman/listinfo/python-list
On 2009-12-11, Neil Cerutti wrote:
> On 2009-12-11, Grant Edwards wrote:
>> [s[1:-1] for s in l if (s[0] == s[-1] == '*')]
>
> That last bit doesn't work right, does it, since an == expression
> evaluates to True or False, no the true or false value itself?
It works for me. Doesn't it work for
On 2009-12-11, Grant Edwards wrote:
> [s[1:-1] for s in l if (s[0] == s[-1] == '*')]
That last bit doesn't work right, does it, since an == expression
evaluates to True or False, no the true or false value itself?
--
Neil Cerutti
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 11 Dec 2009 12:49:42 -0800, Ed Keith wrote:
> I have a problem and I am trying to find a solution to it that is both
> efficient and elegant.
>
> I have a list call it 'l':
>
> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>
> Notice that some of the items in the list
Grant Edwards wrote:
> On 2009-12-11, Ed Keith wrote:
>> I have a problem and I am trying to find a solution to it that is both
>> efficient and elegant.
>>
>> I have a list call it 'l':
>>
>> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>
>> Notice that some of the items in
--- On Fri, 12/11/09, Peter Otten <__pete...@web.de> wrote:
> From: Peter Otten <__pete...@web.de>
> Subject: Re: a list/re problem
> To: python-list@python.org
> Date: Friday, December 11, 2009, 4:24 PM
> Ed Keith wrote:
>
> > I have a problem and I am tryin
Ed Keith wrote:
> I have a problem and I am trying to find a solution to it that is both
> efficient and elegant.
>
> I have a list call it 'l':
>
> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>
> Notice that some of the items in the list start and end with an '*'. I
> wish
l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
Notice that some of the items in the list start and end with an '*'. I wish to
construct a new list, call it 'n' which is all the members of l that start and
end with '*', with the '*'s removed.
So in the case above n would be ['
On 2009-12-11, Ed Keith wrote:
> I have a problem and I am trying to find a solution to it that is both
> efficient and elegant.
>
> I have a list call it 'l':
>
> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
> Notice that some of the items in the list start and end with
> an
2009/12/11 Ed Keith :
> I have a problem and I am trying to find a solution to it that is both
> efficient and elegant.
>
> I have a list call it 'l':
>
> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>
> Notice that some of the items in the list start and end with an '*'. I wish
On Fri, Dec 11, 2009 at 9:49 PM, Ed Keith wrote:
> I have a problem and I am trying to find a solution to it that is both
> efficient and elegant.
>
> I have a list call it 'l':
>
> l = ['asc', '*nbh*', 'jlsdjfdk', 'ikjh', '*jkjsdfjasd*', 'rewr']
>
> Notice that some of the items in the list start
16 matches
Mail list logo