Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Brandon Evans8,154 Points
Is this sort of code frowned upon?
I solved the solution like this:
def sillycase(str): str.split() return str[:(len(str) // 2)].lower() + str[(len(str) // 2):(len(str))].upper()
This honestly looks a little confusing to me at first glance, although from a programmatic standpoint, I figured this was a little bit more efficient than maybe some other approaches. I do not have much experience in DRY or efficient coding so I was just curious if this is something acceptable in the real world or if this is just too confusing and not practical.
Steven Parker216,136 Points
Learning how to make your code more DRY will come with experience, but here's two hints:
- the "str.split()" line doesn't do anything and can be omitted
- the second slice doesn't need a "stop" value
sillycase=['Treehouse'] len=len(sillycase) sillycase=sillycase.upper(0:(len/2+1)+sillycase.lower(len/2::)
What is wrong with mine?