a list/re problem
Grant Edwards
invalid at invalid.invalid
Fri Dec 11 16:02:45 EST 2009
On 2009-12-11, Ed Keith <e_d_k at yahoo.com> 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 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 ['nbh', 'jkjsdfjasd']
[s[1:-1] for s in l if (s[0] == s[-1] == '*')]
--
Grant Edwards grante Yow! Used staples are good
at with SOY SAUCE!
visi.com
More information about the Python-list
mailing list