I need a string/list/generator/comprehension incantation.

Jerry Hill malaclypse2 at gmail.com
Fri Apr 20 13:02:01 EDT 2007


On 4/20/07, Steven W. Orr <steveo at syslang.net> wrote:
> I really tried. I give up.
>
> Now I want something that's going to give me a string whose value is the
> set of all of the first letters of months. Order is not important.

>>> ''.join(set([s[0] for s in calendar.month_abbr[1:]]))
'ADFJMONS'

> And for extra credit, I need the string whose value is the set of all of
> the letters of months minus the first letter.

I'm sure there must be a cleaner way to do this, but it works:
>>> ''.join(set(''.join([s[1:] for s in calendar.month_abbr[1:]])))
'acbeglonprutvy'

> E.g., 'ADFJMONS', 'acbeglonprutvy'


-- 
Jerry



More information about the Python-list mailing list