snipt

Ctrl+h for KB shortcuts
Notice: Snipt is moving away from free accounts on May 1st, 2014. Read more about the transition here.
#1653

Python

Function to Make a List of Tuples

def list_of_tuples(num,value):
	return [(value,i) for i in range(num)]
https://snipt.net/embed/de6f3b415b37f4cb52ec8fa97ace9122/
https://snipt.net/raw/de6f3b415b37f4cb52ec8fa97ace9122/
de6f3b415b37f4cb52ec8fa97ace9122
python
Python
2
2014-04-14T15:06:00
True
False
/api/public/snipt/1653/
list-makeing-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">list_of_tuples</span><span class="p">(</span><span class="n">num</span><span class="p">,</span><span class="n">value</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">return</span> <span class="p">[(</span><span class="n">value</span><span class="p">,</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">num</span><span class="p">)]</span> </span></pre></div> </td></tr></table>
"list comprehension", "return statement", function, tuple
#1652

Python

Iterable Tuple Generator Function

1
2
3
def spam_tuple(num,spam):
	for i in range(num):
		yield (spam,num)
https://snipt.net/embed/fb3bedab52f054802704da956c30f51a/
https://snipt.net/raw/fb3bedab52f054802704da956c30f51a/
fb3bedab52f054802704da956c30f51a
python
Python
3
2014-04-08T17:19:28
True
False
/api/public/snipt/1652/
generator-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">spam_tuple</span><span class="p">(</span><span class="n">num</span><span class="p">,</span><span class="n">spam</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">num</span><span class="p">):</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">yield</span> <span class="p">(</span><span class="n">spam</span><span class="p">,</span><span class="n">num</span><span class="p">)</span> </span></pre></div> </td></tr></table>
"function object iteration", "generator function", function, generator, tuple
#1613

Text only

Inbound Turk Job

$reviewedHit.updateCatalogGroupAttribute("returned_content", "main_content")
https://snipt.net/embed/6760fa21542a7a21ed199ae043562e25/
https://snipt.net/raw/6760fa21542a7a21ed199ae043562e25/
6760fa21542a7a21ed199ae043562e25
text
Text only
1
2014-04-23T14:22:44
True
False
/api/public/snipt/1613/
inbound-turk-job
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a>$reviewedHit.updateCatalogGroupAttribute(&quot;returned_content&quot;, &quot;main_content&quot;) </span></pre></div> </td></tr></table>
"mechanical turk", mturk, velocity
#1517

Python

Iteration Statement

for x in len(some_list):
	print(x, some_list[x])
https://snipt.net/embed/0244e0b239de091515c2406440c5ad00/
https://snipt.net/raw/0244e0b239de091515c2406440c5ad00/
0244e0b239de091515c2406440c5ad00
python
Python
2
2014-04-20T10:03:35
True
False
/api/public/snipt/1517/
sfsd
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">len</span><span class="p">(</span><span class="n">some_list</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">print</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">some_list</span><span class="p">[</span><span class="n">x</span><span class="p">])</span> </span></pre></div> </td></tr></table>
for
#1267

Python

Basic function with nested if/else statement

1
2
3
4
5
def my_function(spam,eggs):
	if len(spam) > 0:
		print(spam, eggs)
	else:
		print('just',eggs)
https://snipt.net/embed/699cd3dcd0fa5a8026f87939d78c88ba/
https://snipt.net/raw/699cd3dcd0fa5a8026f87939d78c88ba/
699cd3dcd0fa5a8026f87939d78c88ba
python
Python
5
2014-04-16T12:57:30
True
False
/api/public/snipt/1267/
basic-function
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="k">def</span> <span class="nf">my_function</span><span class="p">(</span><span class="n">spam</span><span class="p">,</span><span class="n">eggs</span><span class="p">):</span> </span><span id="L-2"><a name="L-2"></a> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">spam</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span> </span><span id="L-3"><a name="L-3"></a> <span class="k">print</span><span class="p">(</span><span class="n">spam</span><span class="p">,</span> <span class="n">eggs</span><span class="p">)</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">else</span><span class="p">:</span> </span><span id="L-5"><a name="L-5"></a> <span class="k">print</span><span class="p">(</span><span class="s">&#39;just&#39;</span><span class="p">,</span><span class="n">eggs</span><span class="p">)</span> </span></pre></div> </td></tr></table>
else, function, if, print