Questions tagged [generator]
A generator is a generalization of a subroutine, primarily used to simplify the writing of iterators. The yield statement in a generator does not specify a co-routine to jump to, but rather passes a value back to a parent routine.
132
questions
2
votes
1
answer
88
views
Is using a generator of context managers kosher?
I know this is not necessarily a problem question but more of a style question. I understand that it doesn't have to be pretty for the most part.
In general, context managers are used for mutexing, ...
4
votes
3
answers
164
views
Improving efficiency of Rust algorithm ported from Python generator
I'm learning Rust by solving ProjectEuler problems.
To this end, I am trying to port a solution to problem 88 (link) in Python that heavily relies on generators to Rust (which doesn't have generators)....
2
votes
1
answer
184
views
Generator for colors
The goal here is to pull an item from an array and when the array ends - to start over - and allow you to pull items infinitely as needed. We don't use PHP that much, so please let us know how we can ...
6
votes
1
answer
2k
views
Date range generator
An app has a feature that's much like any calendar application (like the Outlook calendar for example).
Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...
5
votes
0
answers
200
views
@lazylist - Converts a Python Generator to a List without evaluating every element
Inspired by a blog I read, I made a LazyList class that can wrap an iterable (list, generator etc.) and turn it into a ...
2
votes
2
answers
74
views
Library to Help Loop with Generators
I found I need to loop through a list to create a brute force algorithm. Therefore, I decided to make a library, but to generalize the result by using a generator. There are three cases which is every ...
5
votes
1
answer
124
views
The python code simulates an environment of a disease and calculates how many people get infected
The python code simulates an environment of an X number of persons with an Y number of places they can go to, puts the persons randomly in the places and calculates how many persons get infected, die ...
6
votes
4
answers
772
views
Bidirectional iterate over list in Python
I wrote a short function to iterate over a list starting at a given index, then flipping back and forth between left and right values.
...
3
votes
2
answers
499
views
Q: Paying Debt Off a Year, MIT edX 6.001 U2/PS2/P1
Write a program to calculate the credit card balance after one year if a person only pays the minimum monthly payment required by the credit card company each month.
The following variables contain ...
6
votes
2
answers
389
views
Docstring generator in Google type
Hello everyone!
In this task I had to create docstring generator. I'm just wondering how you see this problem, I have to "take data" from the dictionary
...
1
vote
2
answers
548
views
Racing promises and consuming them in the order of their resolution time
The ideas are
When multiple async calls are made, to be able to start consuming from the first resolving one regardless in what order the promises are fired.
To construct a modern emitter of async ...
6
votes
1
answer
6k
views
Compute the outputs of a generator in parallel
I am processing an unknown "length" of generator object.
I have to keep things "lazy" because of memory management.
The processing is compute heavy, so writing it multiproc style ...
2
votes
1
answer
63
views
Iterating through a list to generate calendars
I'm iterating through a list to generate calendars, the issue is each generator function has the same this.addToCalendar() function. I'd like to know how I could ...
0
votes
2
answers
86
views
Python3: using generator to process a very large list of integers
This is from a leetcode question I am working on. The problem is the following:
create an algorithm that works in the the following fashion:
arr = [1,3,4,8], queries = [[0,1],[1,2],[0,3],[3,3]]
the ...
3
votes
1
answer
68
views
Coroutine-based two-in-one properties
Over the holidays I played around with coroutines and their use as two-in-one getter and setter methods:
...