Now you try!


#1

Since I always like to check what was codecademy solution, I noticed that in your solution there is additional pair of brackets.

cubes_by_four = [x ** 3 for x in range(1, 11) if ((x ** 3) % 4) == 0]
#instead of 

cubes_by_four = [x ** 3 for x in range(1, 11) if (x ** 3) % 4 == 0]


Is there any reason for this since both codes work fine?


#2

looking at the order in which python evaluates the operations;

http://www.informit.com/articles/article.aspx?p=459269&seqNum=11

we can see the modulo operator (%) is handled first, before is equal, so the second set of parentheses is not needed. You could argue to place the parentheses just to be sure, but i wouldn’t


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.