generator-functions

What can you use Python generator functions for?

I'm starting to learn Python and I've come across generator functions, those that have a yield statement in them. I want to know what types of problems that these functions are really good at solving. ...

Distinction between iterator and enumerator

An interview question for a .NET 3.5 job is "What is the difference between an iterator and an enumerator"? This is a core distinction to make, what with LINQ, etc. Anyway, what is the difference? I can't seem to find a solid definition on the net. Make no mistake, I can find the meaning of the two terms but I get slightly different an...

python generator function getting executed twice?

Hello people, I'm using a python generator function to provide me with a list of images in the current directory. However I see the function is giving out the entire list twice instead of one time and I have no idea why. I'm using the Python PIL library to create batch thumbnails. Can anyone point me in the right direction? Thanks in ...

Can I be warned when I used a generator function by accident

I was working with generator functions and private functions of a class. I am wondering Why when yielding (which in my one case was by accident) in __someFunc that this function just appears not to be called from within __someGenerator. Also what is the terminology I want to use when referring to these aspects of the language? Can the ...

Can a Python function take a generator and return generators to subsets of its generated output?

Let's say I have a generator function like this: import random def big_gen(): i = 0 group = 'a' while group != 'd': i += 1 yield (group, i) if random.random() < 0.20: group = chr(ord(group) + 1) Example output might be: ('a', 1), ('a', 2), ('a', 3), ('a', 4), ('a', 5), ('a', 6), ('a', 7), ('a', 8), ('b', 9), ('...

Choosing a syntax for list generating expressions

C# has generator functions which have syntax like: IEnumerable<int> GetNats(int max) { for (int i=0; i < max; ++i) yield return i; } A feature I am interested in for my programming language (a simple object-oriented programming similar to Java, Scala, ActionScript, and C#) are generator expressions. These are essentially syn...

What should happen when a generator function is assigned?

If I have a programming language with first class functions. What should the semantics be when a generator function is shared? For example: var f = function() { foreach (i in 0..42) yield i; } int a = f(); // 0 int b = f(); // 1 // Assigning the generator function var g = f; int c = g(); // ?? int d = f(); // ?? I can i...

Parallel Map (Generator) Operator

I am interested in defining a parallel map operator for my language. It transforms a list into a new list given an expression. It would have a syntax similar to a generator. Unlike generators in C# and Python, it would potentially be evaluated in parallel, if the compiler desires (e.g. there is an idle core, and the list is really big). ...

python report generator from a pdf file

I have a PDF copy of a file for creating a report. Based on this form, we will generate a report. Is there any way that I can fill out the needed fields on the PDF form using python? How? ...

Left hand side of assignment with infinite generators

Sorry to double my earlier question, but I thought to ask specific data which would solve the problem. I want this result tuple_of_vars = (item for _, item for zip(tuple_of_vars, new_vals_generator)) as this is not possible a, b, c, d = (val for val in infite_generator) actually then I want to do in single line for var in var_list...

Fibers in Python

I'm looking for a very simple way to implement fibers in Python. I'm sure there's a really simple way to do it using generators, but my mind is crapping out on me. This isn't for a huge application, so I don't need the fanciness (or the overhead) of something like Diesel or Tornado or Twisted, I just want a neat little way to do fibers. ...