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

Jason Smith
Jason Smith
8,668 Points

Can anyone help? i'm still not sure how i should go about turning a string into a list, then back again.

i can't seem to figure this out

def sillycase(silly):
    newlist = list(silly)
    half = int(len(silly))//2

2 Answers

Jason, You've made a few errors here. First, no need to convert the string to a list. Then when calculating the value of half you do integer division (//) after converting the string length into an integer with int( ) (again, no need, as len will always return an integer). Finally, the string functions upper( ), lower( ) etc. . . do not take arguments. See my solution below:

 def sillycase(string):                             
    half = len(string)//2                   #  calculate half point in string
    first_half = string[:half].lower()      #  use half to slice string and convert to lowercase
    second_half = string[half:].upper()     #  use half to slice string and convert to uppercase
    return first_half + second_half         #  concatenate half strings to return full modified string

Hope this helps

Oleg Zhoglo
Oleg Zhoglo
3,455 Points

What's the difference between / and //?

Hi Oleg,

Division with / will return a float, while // will always return an integer (any fractional remainder is discarded, so this is not like using the math function round, which although returning an integer, will round up or down depending on the fractional remainder). Think of // as the complement to modulo division using % which only returns the remainder.

Jason Smith
Jason Smith
8,668 Points

thanks, that looks alot easier to understand. i didn't know len() always returned an integer, either!