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.
Underscore is just a convention, "k for k,g in groupby(iterable)" also works perfectly.
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
Love this solution! A lot cleaner than the for loop imo
Nice. I learned something new.
This comment is hidden because it contains spoiler information about the solution
I love it.
love learning about new functions! thank you
emmmmm... That's very smart.
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.
Most of the similar solutions here using itertools.groupby() are using "_" for storing the group.
I did not come across this variable naming scheme before. Is it a common convention to use "_" for throwaway variables?
Wouldn't it have the same effect to use
return [ k[0] for k in groupby(iterable)]
?