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

S

Steven W. Orr

I really tried. I give up.

I got this one last time (for which I'm very grateful).

import calendar
months = dict([(month,ii) for ii,month in enumerate(calendar.month_abbr)][1:])

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.

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

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

Thanks in advance to all the wizards out there. :)

--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
 
J

Jon Ribbens

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(m[0] for m in calendar.month_abbr[1:]))
And for extra credit, I need the string whose value is the set of all of
the letters of months minus the first letter.

"".join(set("".join(m[1:] for m in calendar.month_abbr[1:])))

Those are the ways that are obvious to me anyway, maybe there are
better ways. If you actually want a set not a string, remove the
outer-most "".join().
 
S

Scott David Daniels

Steven said:
I really tried. I give up.

I got this one last time (for which I'm very grateful).
... 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.

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

Boy am I sorry we did your homework for you. If you have no idea where
to go, and you can't even show your work, you need to see a TA or
instructor. You are already in over your head; back up and learn to
swim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top