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

slice2 = favourite_things[-2:] I used this, it worked in workspaces but not here. Why is this so? Thanks!

I did what the question asked by creating a new list called slice2 which included the last 2 items from favourite_things.

I typed in slice2 = favourite_things[-2:] however I could not pass the task. May I know why?

THanks!

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 = favourite_things[-2:]

4 Answers

Ahh! Thanks!

Is there a way we can validate british English on this? or is this server set up for americ engli?

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi fl6, it's not about server localisation, the name of the variable you are provided is favorite_things. Python doesn't care about preferred spellings in different countries, a variable name is simply a precise sequence of characters. Every reference to that variable must be spelled exactly the same way.

In theory, you could change the name of the variable when it is declared to favourite_things and then refer to it subsequently as favourite_things. That would make your code self-consistent, but when working on a software project you don't know whether other developers working on other parts of the codebase are depending on that variable existing with that exact name, so you risk breaking the code somewhere else. Always assume that any time you get provided with a name for a variable, that variable will be used somewhere else in the code and thus you shouldn't change it.

Hope that clears everything up for you.

Cheers,

Alex

thanks for that info, as I have to double check my English to American...ok