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

Not working , Why?

not changing favorite things but getting error that i am

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[5 : ]

sorted_things = favorite_things
sorted_things = sorted_things.sort()

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You're doing really well, but the problem here is that you haven't assigned a copy of the favorite_things list to sorted_things but rather a reference to the original list. This means that you are, in fact, changing the original `favorite_things' list. I whipped up a simple demonstration of the difference in a Python workspace and hopefully it will clearly demonstrate the difference between storing a copy of a list and a reference to a list.

fruits1 = ['apple', 'grape', 'banana']

fruits2 = fruits1
print("The original fruits list:")
print(fruits1)
fruits2.append('kiwi')

print("The original fruits list after appending to fruits2:")
print(fruits1)
print("Fruits 2 list:")
print(fruits2)


fruits3 = fruits1[:]
fruits3.append('orange')

print("The fruits list after appending orange to list 3:")
print(fruits1)
print("The third fruits list: ")
print(fruits3)

I highly recommend running this in a workspace and taking a look at the output. It might not be what you expect :smiley: However, I feel confident that you can complete the challenge once you see how this works! But if you're still stuck, let me know! :sparkles:

edited for additional information

In the first part, I assign a reference to the fruits1 list to fruits2. In the second part, I assign a copy of the fruits1 list to fruits3.