<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 29 December 2016 at 18:35, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Thu, Dec 29, 2016 at 7:20 PM, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
> I'd rather add a generator to the itertools<br>
> module:<br>
><br>
> itertools.iterhash(iterable) # yield incremental hashes<br>
><br>
> or, copying the API of itertools.chain, add a method to hash:<br>
><br>
> hash.from_iterable(iterable) # return hash calculated incrementally<br>
<br>
</span>The itertools module is mainly designed to be consumed lazily. The<br>
hash has to be calculated eagerly, so it's not really a good fit for<br>
itertools.</blockquote><div><br></div><div>I understood the "iterhash" suggestion to be akin to itertools.accumulate:<br><br> >>> for value, tally in enumerate(accumulate(range(10))): print(value, tally)<br> ... <br> 0 0<br> 1 1<br> 2 3<br> 3 6<br> 4 10<br> 5 15<br> 6 21<br> 7 28<br> 8 36<br> 9 45<br><br></div><div>However, I think including Ned's recipe (or something like it) in <a href="https://docs.python.org/3/reference/datamodel.html#object.__hash__">https://docs.python.org/3/reference/datamodel.html#object.__hash__</a> as a tool for avoiding large temporary tuple allocations may be a better way to start off as:<br><br></div><div>1. It's applicable to all currently released versions of Python, not just to 3.7+<br></div><div>2. It provides more scope for people to experiment with their own variants of the idea before committing to a *particular* version somewhere in the standard library<br></div><div><br></div></div>Cheers,<br></div><div class="gmail_extra">Nick.<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">Nick Coghlan | <a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a> | Brisbane, Australia</div>
</div></div>