Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (2016, retired 2019) Slices sillyCase

Converting String to List to String

Can someone please advise why this is not correct? I have the function which is supposed to turn a string into a string with the first half lower case and the second half upper case. I have done this by converting the string into a list and then re-joining the combined list.

Would appreciate your help. My apologies if the parentheses in the function are confusing.

sillycase.py
def sillycase(string):
    list1 = list(string)
    first = list1[0:(int((len(list1)/2)+1))].lower()
    second = list1[(int((len(list1)/2)+1)):].upper()
    return "".join(first + second)

2 Answers

hi there, couple of pointers.

  1. list has no .upper() or .lower() attributes
  2. Just use the 'string' passed in as a string is mutable
  3. Revisit your len(string) / 2 + 1 : no need for the + 1

Hope that helps.

Thanks, I passed the challenge.

No need to convert the string into a list.