<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2015-07-03 12:17 GMT+02:00 Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div><div class="h5"><div>On Jul 2, 2015, at 23:28, Pierre Quentel <<a href="mailto:pierre.quentel@gmail.com" target="_blank">pierre.quentel@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-07-03 5:20 GMT+02:00 Andrew Barnert <span dir="ltr"><<a href="mailto:abarnert@yahoo.com" target="_blank">abarnert@yahoo.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><span><div>On Jul 2, 2015, at 03:17, Pierre Quentel <<a href="mailto:pierre.quentel@gmail.com" target="_blank">pierre.quentel@gmail.com</a>> wrote:</div></span><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote"><span>2015-07-02 9:32 GMT+02:00 Andrew Barnert via Python-ideas <span dir="ltr"><<a href="mailto:python-ideas@python.org" target="_blank">python-ideas@python.org</a>></span>:<br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><span><div><div><div>LOn Jul 2, 2015, at 00:12, Nathaniel Smith </div></div></div></span><span><div>You can already do this with accumulate; you just have to write lambda x, _: x*2.</div><div><br></div><div>Of course it doesn't include the built-in bounds, but I don't think you'd want that anyway. With accumulate, you can bound on the domain by passing range instead of count for the input, bound on the range with takewhile, or generate an infinite iterator, or anything else you think might be useful.</div><br><div>Or one more of the various combinations of things you can trivially build out of these pieces might be useful as a recipe ("irange"?) and/or in the third-party more-iterools.</div></span></div><br></blockquote><div><br><span>I am not saying that you can't find other ways to get the same result, just that using a function (usually a lambda) is easier to code and to understand.<br></span></div></div></div></div></blockquote><div><br></div><div>I don't understand how using a function is easier to code and understand than using a function. Or how passing it to range is any simpler than passing it to accumulate, or to a recipe function built on top of accumulate.</div></div></blockquote><div><br></div><div>With the proposed addition to raise, the list of powers of 2 lower than 100 would be :<br><br></div><div>list(range(1, 100, lambda x:x*2))<br><br></div><div>How do you code the same with accumulate ? I tried, but I'm stuck with "stop when the element is >= 100"<br></div></div></div></div></div></blockquote><div><br></div></div></div>A genexpr, a generator function, or a takewhile call.<br><div><br></div><div>I already explained how you could write an "irange" function in two lines out of count, accumulate, and takewhile (along with a variety of other useful things). I also suggested that if this isn't obvious enough, it could be a handy recipe in the docs and/or a useful addition to the third-party more-itertools package. So, given that recipe, you'd write it as:</div><div><br></div><div>    list(irange(1, 100, lambda x:x*2))</div><br><div>There's no need to add a new itertools.orbit (with a custom C implementation), much less to change range into something that's sometimes a Sequence and sometimes not, when a two-line recipe (that's also an instructive sample) does it just as well.</div></div></blockquote></div><br>Well, you still haven't given an example with accumulate, have you ? I expected that. There is a good answer in the reddit thread :<br><br>from itertools import count, takewhile<br>list(takewhile(lambda n: n <= 100, (2**n for n in count())))<br><br>My point here is that even with this simple example, it's not clear even for people who know itertools well to remember which function to use.<br></div></div>