While writing my code for 'anadrome' challenge, I wanted to use groupby from itertools module.
My goal is to sort strings in two groups whether they have an even/odd number of characters.
The result surprised me: there are multiple groups for each key... See my code to get what I mean.
My question : what happens + how can I get it right?
From the docs, "It generates a break or new group every time the value of the key function changes (which is why it is usually necessary to have sorted the data using the same key function)."
It seems that groupby takes only consecutive elements with same value of key function into one group.
When you have for example 'oo', 'll', 'r', 'e', 'nn'
oo and nn will be in one group, then the length's parity changes, so r and e are in another group, and nn goes into new group