Skip to main content

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.

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, ...
georgwalker45's user avatar
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)....
Bram's user avatar
  • 93
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 ...
sheriffderek's user avatar
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 ...
user2190492's user avatar
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 ...
Greedo's user avatar
  • 2,395
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 ...
Akash Patel's user avatar
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 ...
R0Best's user avatar
  • 75
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. ...
Antyos's user avatar
  • 179
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 ...
RacketeerHaskeller's user avatar
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 ...
KermitTheFrog's user avatar
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 ...
Redu's user avatar
  • 906
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 ...
Potter A's user avatar
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 ...
Bonteq's user avatar
  • 153
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 ...
lkilgoretrout's user avatar
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: ...
Richard Neumann's user avatar

15 30 50 per page
1
2 3 4 5
9