What’s the purpose of “send” function on Python generators?

Can someone give me an example of why the “send” function associated with Python generator function exists? I fully understand the yield function. However, the send function is confusing to me. The documentation on this method is convoluted: generator.send(value) Resumes the execution and “sends” a value into the generator function. The value argument becomes the … Read more

Is there a mechanism to loop x times in ES6 (ECMAScript 6) without mutable variables?

The typical way to loop x times in JavaScript is: for (var i = 0; i < x; i++) doStuff(i); But I don’t want to use the ++ operator or have any mutable variables at all. So is there a way, in ES6, to loop x times another way? I love Ruby’s mechanism: x.times do … Read more

How to join two generators in Python?

I want to change the following code for directory, dirs, files in os.walk(directory_1): do_something() for directory, dirs, files in os.walk(directory_2): do_something() to this code: for directory, dirs, files in os.walk(directory_1) + os.walk(directory_2): do_something() I get the error: unsupported operand type(s) for +: ‘generator’ and ‘generator’ How to join two generators in Python? 13 Answers 13