5:41 (as far as I know) mathematically, the correct term is “permutations”, not “combinations”. Combination doesn’t care about order (meaning, ‘AAB’ is the same as ‘ABA’ and ‘BAA’). Just wanted to point that out 😅 edit: you really saved the best for last, starmap and groupby both sound really useful! Thanks for this!
I feel you skipped over what i consider to be the best feature of product(). It takes an arbitrary number of sequences as positional arguments, and will return all combinations of items in those sequences as a sequences of tuples. If you combine this with unpacking, you can avoid the typical antipattern of nesting for loops, with a single for loop.
Would have been better for groupby to just have a sort argument. That implementation does decorate, sort, undecorate, decorate, and group+undecorate, rather than decorate, sort, and group+undecorate. If the key is an expensive operation, you need to do the decorating yourself for performance.
5:41 (as far as I know) mathematically, the correct term is “permutations”, not “combinations”. Combination doesn’t care about order (meaning, ‘AAB’ is the same as ‘ABA’ and ‘BAA’). Just wanted to point that out 😅
edit: you really saved the best for last, starmap and groupby both sound really useful! Thanks for this!
Itertools... Back in the day, it was a revelation for me...
groupby is a powerful function!
I feel you skipped over what i consider to be the best feature of product(). It takes an arbitrary number of sequences as positional arguments, and will return all combinations of items in those sequences as a sequences of tuples. If you combine this with unpacking, you can avoid the typical antipattern of nesting for loops, with a single for loop.
Can zip_longest’s fillvalue be a tuple, such that each list will be “filled” with a correspondingly indexed value from the tuple?
Would have been better for groupby to just have a sort argument. That implementation does decorate, sort, undecorate, decorate, and group+undecorate, rather than decorate, sort, and group+undecorate.
If the key is an expensive operation, you need to do the decorating yourself for performance.
Funny enough, in the word "funny" this groupby code will show us only one vowel sound. But everyone knows there are two vocal letters in this word ))