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.

learn more… | top users | synonyms

7
votes
4answers
135 views
0
votes
1answer
67 views

Speeding up Mersenne prime generator

I am writing a program to calculate Mersenne primes. This code works, but it is so slow: ...
1
vote
0answers
58 views

A class with a function pointer instead of a generator

I am building TiKZ files, one pdf for each image I have. The purpose is to add text to each separately. The images are legion, so I created a script to generate the text files instead of generating ...
7
votes
2answers
264 views

Wrapping my head around generators

I am going on with refactoring my code base while migrating from Python 2 to Python 3. I am using generators to make reusable components this time as I am more comfortable with them this time then ...
5
votes
3answers
370 views

Optimization for SQLite result set parsing

I am retrieving information from an SQLite database that gives me back around 20 million rows that I need to process. This information is then transformed into a dict of lists which I need to use. I ...
3
votes
2answers
333 views

Searching a 2D matrix for a consecutive sequence

I've been solving problems on checkio (and trying to digest other's code) in order to improve my Python. My main goals are to learn to write more idiomatic Python and to explore the language more ...
2
votes
1answer
174 views

Is it feasible to rewrite this code using list comprehension or a generator function?

I wrote the following code to parse some weak ciphers out of an nmap.xml report. I am wondering if there is a more elegant way to write this code in order to avoid the nested for loops with the double ...
0
votes
1answer
219 views

Filtering a long list of files through a set of ignore patterns using iterators

I have a backup job that walks across a huge directory with potentially millions of files. Python's os.walk() works just fine. Now, I have implemented a feature to ignore files based in a black list ...
0
votes
1answer
213 views

Random string generator [closed]

I have made a simple number generator, and I have a question: is it possible for the generator to eject "red", "blue", "green", " yellow" and "white" instead of the numbers 1-5? ...
3
votes
1answer
226 views

Subscriptable/Indexable generator

I'm not a Python developper, but I enjoy programming with it, and for a project I wanted to have generators that I can easily index. Using python's slice model is obviously the way to go, and here's ...
1
vote
1answer
222 views

DFS algorithm with generators

Background: I was working on a project were I needed to write some rules for text-processing. After working on this project for a couple of days and implementing some rules, I realized I needed to ...
4
votes
3answers
6k views

Random String generator in C

I created this small function just to practice C code. It's a simple random string generator. ...
1
vote
2answers
503 views

Generator to Tuple to List?

I have a method that takes a generator, converts it into a tuple to sort it, then into a list. It works perfectly, but being as I am fairly new to the Python world, I keep asking myself if it is worth ...
2
votes
1answer
312 views

Efficiency of Recursive Checkers Legal Move Generator

I'm implementing a checkers engine for a scientific experiment. I found out through profiling that this is one of the functions that takes up a lot of time. I'm not looking for an in-depth analysis, ...
2
votes
0answers
250 views

Reading from a file and connect all data in one big data than to use generators

Is there better way to read from a file and connect all data in one big data than to use generators? At the moment, I do the following: use generators to read data from files. use NumPy to pack all ...
2
votes
1answer
383 views

Discrete random variable generator

There is my SSCCE to generate a value of discrete random variable. values is set of value the RV can take and procents is ...
4
votes
0answers
486 views

Iterator and Generator versions of Python's range()

I have created iterator and generator versions of Python's range(): Generator version: ...
1
vote
1answer
240 views

Objective-C CF Random Name Generator

Based on a python name generator grammar I found here I've decided to write my own in objective-C. The idea is I can load the grammar from a plist file and generate random names from it. I'm looking ...
3
votes
3answers
223 views

Simple randomization program

I'm a few months into learning C++ programming and I want to know if I'm moving generally in the right direction or not with the following code. This is the most advanced thing I've created so far, ...
3
votes
2answers
328 views

Text parser implemented as a generator

I often need to parse tab-separated text (usually from a huge file) into records. I wrote a generator to do that for me; is there anything that could be improved in it, in terms of performance, ...
1
vote
2answers
160 views

Can this python generator be made more efficient?

I'm trying to get a better grasp on generators in python because I don't use them enough (I think generators are cool). To do so I wrote a generator for prime numbers: ...
1
vote
2answers
346 views

Random Topic Generator

I've written a python module that randomly generates a list of ideas that can be used as the premises for furthur research. For instance, it would be useful in situations where a new thesis topic is ...
2
votes
2answers
365 views

Python generator to produce lattice points on an n-simplex.

Looking for a code review, and hopefully to learn something if someone has a nicer solution. Here's what I wrote: ...
7
votes
4answers
829 views

Generator expressions or yield generators?

This is a revisit to a question already asked here about a year and a half ago. While solving Project Euler's Problem 40 I wrote this: ...
1
vote
2answers
3k views

Python generator function that yields combinations of elements in a sequence sorted by subset order

In Python, itertools.combinations yields combinations of elements in a sequence sorted by lexicographical order. In the course of solving certain math problems, I ...