snipt

Ctrl+h for KB shortcuts

Python

Pass lists to dict()

1
2
3
4
5
6
>>> i
['a', 'b']
>>> l
[1, 2]
>>> dict([i,l])
{'a': 'b', 1: 2}
https://snipt.net/embed/1adca8ff7fa6bc60b1885a58c1202562/
/raw/1adca8ff7fa6bc60b1885a58c1202562/
1adca8ff7fa6bc60b1885a58c1202562
python
Python
7
2019-06-13T02:32:25
True
False
False
/api/public/snipt/3960/
pass-lists-to-dict
<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> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="o">&gt;&gt;&gt;</span> <span class="n">i</span> </span><span id="L-2"><a name="L-2"></a><span class="p">[</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">]</span> </span><span id="L-3"><a name="L-3"></a><span class="o">&gt;&gt;&gt;</span> <span class="n">l</span> </span><span id="L-4"><a name="L-4"></a><span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]</span> </span><span id="L-5"><a name="L-5"></a><span class="o">&gt;&gt;&gt;</span> <span class="nb">dict</span><span class="p">([</span><span class="n">i</span><span class="p">,</span><span class="n">l</span><span class="p">])</span> </span><span id="L-6"><a name="L-6"></a><span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="s1">&#39;b&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">:</span> <span class="mi">2</span><span class="p">}</span> </span></pre></div> </td></tr></table>
dictionary, list, python

Python console session

Explode / Implode List

1
2
3
4
5
6
7
>>> V = list(V)
>>> V
['s', 'p', 'a', 'm', 'm', 'y']
>>> V = ''.join(V)
>>> V
'spammy'
>>>
https://snipt.net/embed/ea338a886e79cbae201c6eb794f72689/
/raw/ea338a886e79cbae201c6eb794f72689/
ea338a886e79cbae201c6eb794f72689
pycon
Python console session
7
2019-06-30T06:07:29
True
False
False
/api/public/snipt/3218/
explode-implode-list
<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> <a href="#L-6">6</a> <a href="#L-7">7</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">V</span><span class="p">)</span> </span><span id="L-2"><a name="L-2"></a><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> </span><span id="L-3"><a name="L-3"></a><span class="go">[&#39;s&#39;, &#39;p&#39;, &#39;a&#39;, &#39;m&#39;, &#39;m&#39;, &#39;y&#39;]</span> </span><span id="L-4"><a name="L-4"></a><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">V</span><span class="p">)</span> </span><span id="L-5"><a name="L-5"></a><span class="gp">&gt;&gt;&gt; </span><span class="n">V</span> </span><span id="L-6"><a name="L-6"></a><span class="go">&#39;spammy&#39;</span> </span><span id="L-7"><a name="L-7"></a><span class="go">&gt;&gt;&gt;</span> </span></pre></div> </td></tr></table>
list, python

Bash

command line to quickly list processes owned by or called myproc

ps aux | grep myproc
https://snipt.net/embed/9b8341bdbfed7b333a29056100f26b80/
/raw/9b8341bdbfed7b333a29056100f26b80/
9b8341bdbfed7b333a29056100f26b80
bash
Bash
1
2019-07-04T09:56:14
True
False
False
/api/public/snipt/3178/
command-line-to-quickly-list-processes-owned-by-or-called-myproc
<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></span><span id="L-1"><a name="L-1"></a>ps aux <span class="p">|</span> grep myproc </span></pre></div> </td></tr></table>
commandline, identify, linux, list, locate, name, process, processes, unix, user