As cool as they look when you write them, comprehensions this dense obfuscate your code. Splitting this into multiple lines helps, but it would be much easier to understand as a normal for loop.
If the goal is to just know the number of items in each slot, here is the first thing that came to my mind (and does not require any iteration):
Agreed. Don't see where iteration would be needed here if knowing group size is the actual goal.
It looks like a blog post that arrives at "this is essentially what the modulo operator does for you", but with an O(n) algorithm.
However, add a step inside that iterative loop that chooses, at random and without repeats, the actual named employees that will be in these meetings (which I believe will be the point), and none of this matters anyway, since you will wind up with something that is worse than O(n) anyway. You intrinsically have to iterate over the entire list and then, somehow, also choose employees at random, which cannot be "free" in computational terms.
The author wants leftovers to be evenly distributed. For example for n=15 and g=4 he wants [5,5,5].
I think his very first 3 liner is the most readable version. If we're microoptimizing, his comprehension version also has a lot of extra divisions. I would write something like this instead:
At the bottom of the Python doc page for itertools are “more itertools” in which the functions “grouper” and “roundrobin” seem to do the trick. Overkill?
I understood it to be a way to help employees feel connected to their coworkers in a way similar to what would happen naturally in an office setting. Many of us struggle with this.
Setting up of SkypeForBusiness, Zoom, Teams, Webex conferences based on that and on times that are coordiated with the users calendars - THAT would be awesome.
It woud be a true serendipity experience - meeting people in your company you do not know.
The article starts with "We've been experimenting with breaking up employees into random groups (of size 4)." How does stopping at a list of group sizes (numbers) help you do that?
Oh man. Take a chill pill. We've got a ton more meaty posts coming, just skip this light one, have a good Saturday. We've got "comparison of different ARM processors", "detailed look at how executables work", "benefits of stale DNS with Consul", an analyst report and a series on designing our Teams product.
I actually wrote that post because the internal blog pipeline at Cloudflare had dried up. By posting it and cajoling people I managed to get a whole load of posts to appear (I bet some of those people were thinking "I can do better than THAT!")
This problem has a name actually - there’s a solution called Bjorklund’s algorithm which was originally used in physics. It was picked up by a music researcher (Godfried Toussaint) who noticed that it generates satisfying rhythms too. https://en.m.wikipedia.org/wiki/Euclidean_rhythm I implemented it myself for Sonic Pi as the spread function.
If the goal is to just know the number of items in each slot, here is the first thing that came to my mind (and does not require any iteration):