Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
It's a method to ignore specific values.
For instance:
a,_,b = (1,2,3)
Then: a=1 and b=3
Another example:
a,*_, b = (1,2,3,4,5,6,7,8)
a = 1 and b = 8
Other function to this is save the last result in "_" variable.
So if you do this:
2+4 -> result= 6
_ -> result= 6 #save the last result in your program.
For separate numbers:
But you can do:
This link helps so much: https://www.datacamp.com/tutorial/role-underscore-python
If you slice sequences by specifying out of bound index, it will slice the sequence to nearest index
i believe it works due to fact that value of arr[:i+1] is not being called as ending value is not included in a slice of list.
Example:
arr = [1,2,3,4,5]
len(arr) = 5
[i for i in range(5)] --> i = [0,1,2,3,4]
len(arr) --> IndexError
arr[:i] -> arr[:4] --> [1,2,3,4]
arr[:i+1] -> arr[:5] --> [1,2,3,4,5]
I think I was playing around with diffetent solutions and accidently forget to remove the import.
Added a note.
.
It seems that in the Python of this, the same object is passed as a variable to the function, and is also used to test the result. I haven't encountered this in other exercises before.
I just resolved this issue in my own solution, but it seems several people are frustrated by this problem. This seems to be causing unnecessary hassle for people - maybe it's worth changing?
I agree, this issue is not resolved - I am having the same issue.
Input array:
[7, 0, 'z', 'c', 0, 7, 0, 'z', 'c', 0, 8, 0, 'y', -6, 'b', 0, 0, False, 2, 9, 8, -4, 0, 0, -2, False, -7, -9, -2, 0, -6, 'pippi', 0, 'z']
My function's output:
[7, 'z', 'c', 7, 'z', 'c', 8, 'y', -6, 'b', False, 2, 9, 8, -4, -2, False, -7, -9, -2, -6, 'pippi', 'z', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
The test's expected output:
[7, 'z', 'c', 7, 'z', 'c', 8, 'y', -6, 'b', False, 2, 9, 8, -4, -2, False, -7, -9, -2, -6, 'pippi', 'z']
There are no zeros in the expected output - this appears to be a mistake.
No.
You mutated the input.
It's worse than that.
I thought to hard code the right thing for the basic tests and the zero elimination for the random tests. I then hit some random tests that do result in zeros at the end of the expected output.
So, it is completely borked.
Yes, and it will even keep the value, (i.e., _ is a valid variable name, and is not special in any way other than by convention). It's just seen as slightly more "Pythonic" to use _ as a sign that you're ignoring a value.