+ 12
I often change the parameters in the code to better understand. This output is unclear to me?
2 ответов
+ 4
Range() with 1 parameter gives you a list of integers from 0 going up to but not including the parameter. Since -8 < 0, range(-8) doesn’t do anything. If you pass a second parameter to the range function, the first number replaces 0 as the start number, then it goes up to but not including the second parameter.
If you do range(-8, 0) you should see a different result.
+ 2
The accumulate function goes something like this:
0 = 0
1 = 0 + 1
3 = 0 + 1 + 2
6 = 0 + 1 + 2 + 3
10 = 0 + 1 + 2 + 3 + 4
15 = 0 + 1 + 2 + 3 + 4 + 5
and so on...
while the takewhile function iterates through the list elements and gets that element if it satisfies the given expression in the function.