Popular recipes by SnarkTurne http://code.activestate.com/recipes/users/4185559/2013-07-16T14:03:08-07:00ActiveState Code RecipesGenerates tuples of integers with a given sum (Python)
2013-07-16T14:03:08-07:00SnarkTurnehttp://code.activestate.com/recipes/users/4185559/http://code.activestate.com/recipes/578608-generates-tuples-of-integers-with-a-given-sum/
<p style="color: grey">
Python
recipe 578608
by <a href="/recipes/users/4185559/">SnarkTurne</a>
.
Revision 3.
</p>
<p>This is a generator that generates all tuples of n integers (>=0) with a given sum s.
The generator can make the difference between tuples (3,0,0) and (0,3,0) or not (see order parameter). </p>
Evaluates string embedded expressions (rubstr module) (v 0.91) (Python)
2013-03-09T12:22:00-08:00SnarkTurnehttp://code.activestate.com/recipes/users/4185559/http://code.activestate.com/recipes/578487-evaluates-string-embedded-expressions-rubstr-modul/
<p style="color: grey">
Python
recipe 578487
by <a href="/recipes/users/4185559/">SnarkTurne</a>
.
Revision 2.
</p>
<p>This recipe allow you to write :</p>
<pre class="prettyprint"><code>>>> a,b=5,6
>>> rstr("If you add #{a} and #{b}, you'll get #{a+b}.")
If you add 5 and 6, you'll get 11.
</code></pre>
<p>This is more readble, from my point of view, than :</p>
<pre class="prettyprint"><code>"If you add {} and {}, you'll get {}.".format(a,b,a+b)
</code></pre>
<p>This recipe is inspired from the way Ruby evaluates strings :</p>
<pre class="prettyprint"><code>irb> a,b=5,6
irb> "If you add #{a} and #{b}, you'll get #{a+b}."
==> If you add 5 and 6, you'll get 11.
</code></pre>