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 Back and Forth

Alright, let's make this last step a bit harder and do two things. Make a copy of favorite_

I made a copy of favorite _things and called the copy sorted_things[:] then appended .sort() tired of watching the movie, what am I doing wrong here.

Thanks Joe

slices.py
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[1:4]
slice2 = favorite_things[-2:]
favorite_things = sorted_things[:].sort() # favorite_thingd = sorted_things[:] should make a copy of original list, right?
                                           # then append .sort() should sort the new list, right?
                                           # why does this code return Task 1 is no longer passing?

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

There are two errors in your code. First it seems what you really wanted was to make a copy of favorite_things, then sort it and assign it to sorted_things. Something like:

sorted_things = favorite_things[:].sort()

The issue with this approach is that .sort() sorts a list in-place and returns None. This means that the new temporary list favorite_things[:] does get sorted in place, but it is the return value None that gets assigned to sorted_things.

To correct this, break the statement into two parts:

sorted_things = favorite_things[:]  # sorted_things get the copy
sorted_things.sort()  # sorted_things is sorted in-place

Post back if you need more help. Good Luck!!

Thank you sir. I had my head pointed the wrong way. But I bet I remember that kind hint. Thanks Joe

sorted_things = favorite_things[:] # sorted_things get the copy sorted_things.sort()