Skip to content

Commit

Permalink
Improving doc (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
turulomio authored Dec 23, 2023
1 parent e870f66 commit 4cdf78d
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 21 deletions.
41 changes: 34 additions & 7 deletions docs/_sources/lod.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ lod.dod2lod(dod)
```

## lod2dictkv
Converts a list of dictionaries (lod) to a dictionary using a key for the new key and another key for its value


```{code-cell}
from pydicts import lod
lod_=[{"a":1,"b":2}, {"a":3,"b":4}]
lod.lod2dictkv(lod_,"a","b")
```


## lod2dod

Expand All @@ -52,18 +62,35 @@ lod.lod2list(lod_,"a")
## lod2list_distinct

Converts a list of dictionaries (lod) to list using all distinct values of key
``` python
>>> from pydicts import lod
>>> lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
>>> lod.lod2list_distinct(lod_,"b")
[2, 4]
>>> lod.lod2list(lod_,"b")
[2, 4, 4]

```{code-cell}
from pydicts import lod
lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
print("lod2list:",lod.lod2list(lod_,"a"))
print("lod2list_distinct:",lod.lod2list_distinct(lod_,"a"))
```


## lod2lol

Converts a list of dictionaries (lod) to a list of lists

If you don't select keys (Supposed ordereddict)

```{code-cell}
from pydicts import lod
lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
lod.lod2lol(lod_)
```

You can select your keys in the order you need

```{code-cell}
from pydicts import lod
lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
lod.lod2lol(lod_,["b","a"])
```

## lod2lood

## lod_average
Expand Down
66 changes: 60 additions & 6 deletions docs/lod.html
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ <h2>dod2lod<a class="headerlink" href="#dod2lod" title="Permalink to this headin
</section>
<section id="lod2dictkv">
<h2>lod2dictkv<a class="headerlink" href="#lod2dictkv" title="Permalink to this heading">#</a></h2>
<p>Converts a list of dictionaries (lod) to a dictionary using a key for the new key and another key for its value</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pydicts</span> <span class="kn">import</span> <span class="n">lod</span>
<span class="n">lod_</span><span class="o">=</span><span class="p">[{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="mi">2</span><span class="p">},</span> <span class="p">{</span><span class="s2">&quot;a&quot;</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">:</span><span class="mi">4</span><span class="p">}]</span>
<span class="n">lod</span><span class="o">.</span><span class="n">lod2dictkv</span><span class="p">(</span><span class="n">lod_</span><span class="p">,</span><span class="s2">&quot;a&quot;</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>{1: 2, 3: 4}
</pre></div>
</div>
</div>
</div>
</section>
<section id="lod2dod">
<h2>lod2dod<a class="headerlink" href="#lod2dod" title="Permalink to this heading">#</a></h2>
Expand Down Expand Up @@ -468,17 +483,56 @@ <h2>lod2list<a class="headerlink" href="#lod2list" title="Permalink to this head
<section id="lod2list-distinct">
<h2>lod2list_distinct<a class="headerlink" href="#lod2list-distinct" title="Permalink to this heading">#</a></h2>
<p>Converts a list of dictionaries (lod) to list using all distinct values of key</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">pydicts</span> <span class="kn">import</span> <span class="n">lod</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lod_</span><span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">}]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lod</span><span class="o">.</span><span class="n">lod2list_distinct</span><span class="p">(</span><span class="n">lod_</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">)</span>
<span class="go">[2, 4]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lod</span><span class="o">.</span><span class="n">lod2list</span><span class="p">(</span><span class="n">lod_</span><span class="p">,</span><span class="s2">&quot;b&quot;</span><span class="p">)</span>
<span class="go">[2, 4, 4]</span>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pydicts</span> <span class="kn">import</span> <span class="n">lod</span>
<span class="n">lod_</span><span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">}]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;lod2list:&quot;</span><span class="p">,</span><span class="n">lod</span><span class="o">.</span><span class="n">lod2list</span><span class="p">(</span><span class="n">lod_</span><span class="p">,</span><span class="s2">&quot;a&quot;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;lod2list_distinct:&quot;</span><span class="p">,</span><span class="n">lod</span><span class="o">.</span><span class="n">lod2list_distinct</span><span class="p">(</span><span class="n">lod_</span><span class="p">,</span><span class="s2">&quot;a&quot;</span><span class="p">))</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>lod2list: [1, 3, 3]
lod2list_distinct: [1, 3]
</pre></div>
</div>
</div>
</div>
</section>
<section id="lod2lol">
<h2>lod2lol<a class="headerlink" href="#lod2lol" title="Permalink to this heading">#</a></h2>
<p>Converts a list of dictionaries (lod) to a list of lists</p>
<p>If you don’t select keys (Supposed ordereddict)</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pydicts</span> <span class="kn">import</span> <span class="n">lod</span>
<span class="n">lod_</span><span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">}]</span>
<span class="n">lod</span><span class="o">.</span><span class="n">lod2lol</span><span class="p">(</span><span class="n">lod_</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[1, 2], [3, 4], [3, 4]]
</pre></div>
</div>
</div>
</div>
<p>You can select your keys in the order you need</p>
<div class="cell docutils container">
<div class="cell_input docutils container">
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pydicts</span> <span class="kn">import</span> <span class="n">lod</span>
<span class="n">lod_</span><span class="o">=</span> <span class="p">[{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">},</span> <span class="p">{</span><span class="s1">&#39;a&#39;</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">:</span> <span class="mi">4</span><span class="p">}]</span>
<span class="n">lod</span><span class="o">.</span><span class="n">lod2lol</span><span class="p">(</span><span class="n">lod_</span><span class="p">,[</span><span class="s2">&quot;b&quot;</span><span class="p">,</span><span class="s2">&quot;a&quot;</span><span class="p">])</span>
</pre></div>
</div>
</div>
<div class="cell_output docutils container">
<div class="output text_plain highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>[[2, 1], [4, 3], [4, 3]]
</pre></div>
</div>
</div>
</div>
</section>
<section id="lod2lood">
<h2>lod2lood<a class="headerlink" href="#lod2lood" title="Permalink to this heading">#</a></h2>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 34 additions & 7 deletions jupyter/lod.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ lod.dod2lod(dod)
```

## lod2dictkv
Converts a list of dictionaries (lod) to a dictionary using a key for the new key and another key for its value


```{code-cell}
from pydicts import lod
lod_=[{"a":1,"b":2}, {"a":3,"b":4}]
lod.lod2dictkv(lod_,"a","b")
```


## lod2dod

Expand All @@ -52,18 +62,35 @@ lod.lod2list(lod_,"a")
## lod2list_distinct

Converts a list of dictionaries (lod) to list using all distinct values of key
``` python
>>> from pydicts import lod
>>> lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
>>> lod.lod2list_distinct(lod_,"b")
[2, 4]
>>> lod.lod2list(lod_,"b")
[2, 4, 4]

```{code-cell}
from pydicts import lod
lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
print("lod2list:",lod.lod2list(lod_,"a"))
print("lod2list_distinct:",lod.lod2list_distinct(lod_,"a"))
```


## lod2lol

Converts a list of dictionaries (lod) to a list of lists

If you don't select keys (Supposed ordereddict)

```{code-cell}
from pydicts import lod
lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
lod.lod2lol(lod_)
```

You can select your keys in the order you need

```{code-cell}
from pydicts import lod
lod_= [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}, {'a': 3, 'b': 4}]
lod.lod2lol(lod_,["b","a"])
```

## lod2lood

## lod_average
Expand Down

0 comments on commit 4cdf78d

Please sign in to comment.