Hello, everybody!
Trying to solve the problem in the subj, I found that I miss some
iterator-related tools. Mostly consequental application of the same
function to some argument (if I'm not missing something it has a name
y-combinator).
If we had one, generating the sequence of digits is easy:
iter(y(lambda (q, _): divmod(q, n), (x, 0)).next, (0, 0))
and if we have something like this in itertools
def y(f, x):
while True:
yield x
x = f(x)
it might be one of simplest solutions possible.
I tried to emulate it in the way Bengt wrote his solution:
def y(f, x):
return (h for t in [itertools.repeat(x)] for h, t in iter(lambda:
(t.next(), itertools.imap(f, t)), None))
but it, should I say, a little bit too complex
Therefore, a couple of questions:
1) is there easier way to write y with genexps?
2) don't we need y in itertools?
Partially answering the second question: of course, y is too abstract
and, at least IMHO, doesn't fit Python ideology. However, most of
itertools IMHO is rather abstract :)
With the best regards,
anton. 1 1261
Oops, it not y-combinator itself, but rather releated thing, sorry.
And as followup: iter(callable, sentinel) seems a little bit too
restricted for me. The reason is simple: no params are passed to
callable and, therefore, it is usually should return the same value. Of
course, there are a lot of callable things in Python that don't behave
this way, but shouldn't iter have interface like iter(callable, params)
that would generated iterator [x, f(x), f(f(x)), ...] that can be stoped
with itertools.takewhile if needed?
with the best regards,
anton. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Mars |
last post by:
I have looked long and hard at Mr. Martelli's Borg recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531
It is a very useful substitute for a Singleton, but I can't figure out...
|
by: Francis Avila |
last post by:
Below is an implementation a 'flattening' recursive generator (take a nested
iterator and remove all its nesting). Is this possibly general and useful
enough to be included in itertools? (I know...
|
by: Dave Benjamin |
last post by:
It's nice to see you around here again!
Dave
|
by: Robert Brewer |
last post by:
def warehouse(stock, factory=None):
"""warehouse(stock, factory=None) -> iavailable, iremainder.
Iterate over stock, yielding each value. Once the 'stock' sequence
is
exhausted, the factory...
|
by: Steven Bethard |
last post by:
Jack Diederich wrote:
>
> itertools to iter transition, huh? I slipped that one in, I mentioned
> it to Raymond at PyCon and he didn't flinch. It would be nice not to
> have to sprinkle 'import...
|
by: Steven Bethard |
last post by:
Michael Spencer wrote:
> While we're on the topic, what do you think of having unary,
> non-summary builtins automatically map themselves when called with an
> iterable that would otherwise be an...
|
by: Ron Guerin |
last post by:
The New York Linux User's Group invites you to a special presentation
by Alex Martelli of Google, on the Python Object Model. This
presentation will be held at P.J. Clarke's Sidecar, rather than...
|
by: Ron Guerin |
last post by:
(date and time inadvertently omitted last time. sorry!)
The New York Linux User's Group invites you to a special presentation
by Alex Martelli of Google, on the Python Object Model. This...
|
by: rurpy |
last post by:
The code below should be pretty self-explanatory.
I want to read two files in parallel, so that I
can print corresponding lines from each, side by
side. itertools.izip() seems the obvious way
to...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |