3 ms·
Note that this approach doesn't work as nicely if you need to store additional information alongside the name and count.
by Denvercoder9 5y ago
Note that this approach doesn't work as nicely if you need to store additional information alongside the name and count.
- qsort 5y agoIf you need to store other info, it doesn't make sense to aggregate. Think of it in SQL: SELECT a, b, SUM(c) FROM table GROUP BY a doesn't even compile. You either project away `b` or group over both `a` and `b`.
- Denvercoder9 5y agoThat's true, but while in SQL you can easily group by `a` and `b`, here that's difficult (you'll need to key the dict by a tuple of the values, and reassemble the dictionary afterwards, or something like that).
- qsort 5y agoYeah, fair enough. You'd have the same problem with any approach, though. In a sense, that's easy in SQL only because the hash-magic is abstracted away.