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 trialAndras Andras
8,230 PointsHow to sort() strings?
Hello,
Regarding the 3rd step of the 1st Slice exercise I checked the documentation but I have not found how to sort strings with sort() but sorted(). Could you give me a little hint how to start, please.
favorite_things = ['raindrops on roses', 'whiskers on kittens', 'bright copper kettles',
'warm woolen mittens', 'bright paper packages tied up with string',
'cream colored ponies', 'crisp apple strudels']
slice1 = favorite_things [:]
slice1 = slice1[1:4]
slice2 = favorite_things [:]
slice2 = slice2[5:]
sorted_things = favorite_things[:]
sorted_things = sorted_things.sort()
1 Answer
Steve Hunter
57,712 PointsHi Andras,
You're correct that there's no method called sorted()
(that I'm aware of). The challenge wants you to use sort()
on the copy of favorite_things
which is called sorted_things
simply because the list has had sort()
applied to it.
My code looked like this:
slice1 = favorite_things[1:4]
slice2 = favorite_things[-2:]
sorted_things = favorite_things[:]
sorted_things.sort()
I hope that helps,
Steve.