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

jmac pd
jmac pd
11,490 Points

should return half lower and half upper right?

maybe I'm just making the code way too complicated than it should be but I ran this with a few examples and it did do what was instructed.

Am I missing something here?

sillycase.py
def sillycase(string):
    string1=[]
    string2=[]
    string = list(string)
    half = len(string)//2
    for i in string[:half]:
        string1.append(i.lower())
    for i in string[half:]:
        string2.append(i.upper())
    string = string1+string2
    string[:]=[''.join(string[:])]
    return string

2 Answers

andren
andren
28,558 Points

Slices work on strings just like they do on lists, so there is no need to convert the string to a list.

You can just slice the strings directly and lower/upper case them like this:

def sillycase(string):
    half = len(string)//2
    return string[:half].lower() + string[half:].upper()
jmac pd
jmac pd
11,490 Points

NVM got it, was returning a list.

I just added return string.pop(0) and it was fine haha but a more efficient way to write this would be read if it was posted =)