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 trialkeith frazier
Python Development Techdegree Student 5,771 PointsUnique Set vs Redundant List
I am unsure how the list works at 10:19. The other loops he creates are pretty self explanatory like how the grid with ranges 1-4 and 1-10 had a combination of each case in each range. Can someone explain this loop a little better, specifically why each number is generated?
[round(x,y) for y in range(1, 11) for x in range(2, 21)]
In the video he gets a list that has many repeating numbers like 1, 1, 1, 1, 2, 2, 2, 2, etc. But when I run the code myself I get the following:
>> [round(x,y) for y in range(1,11) for x in range(2,21)]
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
None of the numbers repeat themselves right after each other. What is the difference in what the video is doing and what I am doing?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsIt seems you have a typo. Perhaps you meant round(x/y)
instead of "round(x, y)". By using a comma, the second argument is the number of places to round to, but since x
is always an integer, you always get itself back after the rounding. See docs.
Post back if you have more questions. Good luck!