<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Jul 6, 2018 at 12:26 PM, Franklin? Lee I use this kind of function in several different projects over the<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
years, and I rewrote it many times as needed.<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I added several options, such as:<br>
- key function<br>
- value function<br>
- "ignore": Skip values with these keys.<br>
- "postprocess": Apply a function to each group after completion.<br>
- Pass in the container to store in. For example, create an<br>
OrderedDict and pass it in. It may already hold items.<br>
- Specify the container for each group.<br>
- Specify how to add to the container for each group.<br></blockquote><div><br></div><div>interesting...</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Then I cut it down to two optional parameters:<br>
- key function. If not provided, the iterable is considered to have<br>
key-value pairs.<br>
</blockquote><div><br></div><div>OK -- seems we're all converging on that :-)</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">- The storage container.<br></blockquote><div><br></div><div>so this means you'r passing in a full set of storage containers? I'm a vit confused by that -- if they might be pre-populated, then they would need to be instance,s an you'd need to have one for every key -- how would you know in advance aht you needed???</div><div><br></div><div>I played around with passing in a optional storage object:</div><div><br></div><div><a href="https://github.com/PythonCHB/grouper/commit/d986816905406ec402724beaed2b88c96df64469">https://github.com/PythonCHB/grouper/commit/d986816905406ec402724beaed2b88c96df64469</a><br></div><div><br></div><div>but as we might want a list or a set, or a Counter, or ??? it got pretty ugly, as lists and sets and Counters all have different APIs for adding stuff. So I gave up and figured just saying "it's always a list) made the most sense.</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Finally, I removed the key function, and only took pairs and an<br>
optional container. However, I don't remember why I removed the key<br>
function. It may be that I was writing throwaway lambdas, and I<br>
decided I might as well just write the transformation into the<br>
comprehension.</blockquote><div><br></div><div>exactly -- but I suspect hat may be because you where writing a comprehension anyway, as you needed to manipulate the values, also -- so if there were a value function, you could use either API.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I think a key function is worth having.<br></blockquote><div><br></div><div>I think there's more or less consensus on that too.</div><div><br></div><div>-CHB</div><div> </div><div><br></div><div><br></div><div>-- </div></div><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>