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

Slicing a slice

This isn't a question, rather an observation. In s2v4.py she uses slicing to remove the first line from data_sample. She then calls calculate_sum from s2v3.py on data_sample, which itself uses slicing to remove the first line of what it receives. This results in the first two lines being sliced, resulting in an incorrect average.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,468 Points

Good point. Can you tag the video where this is happening?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,468 Points

I agree that the header is automatically removed in s2v3.data_sample() as shown at 02:00 in the calculating sums and totals video.

In the next video, the s2v4.find_average() function is defined correctly, but in the call to the function, the argument has the header pre-removed using a [1:] slice as shown at 02:10 in the calculate averages video. At 02:50 in the same video, an option header parameter is added that doesn't remove the header by default. It's clear at 07:55, that the usage of this parameter still causes a second header removal when calculating the first half data average, effectively removing two headers.

Tagging Craig Dennis to make a note for future course update corrections.