Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4723a30

Browse files
committed
List and Datetime
1 parent 017bb13 commit 4723a30

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if __name__ == '__main__': # Runs main() if file wasn't imported.
2929
List
3030
----
3131
```python
32-
<list> = <list>[from_inclusive : to_exclusive : ±step_size]
32+
<list> = <list>[<slice>] # Or: <list>[from_inclusive : to_exclusive : ±step]
3333
```
3434

3535
```python
@@ -38,10 +38,10 @@ List
3838
```
3939

4040
```python
41-
<list>.sort()
42-
<list>.reverse()
43-
<list> = sorted(<collection>)
44-
<iter> = reversed(<list>)
41+
<list>.sort() # Sorts in ascending order.
42+
<list>.reverse() # Reverses the list in-place.
43+
<list> = sorted(<collection>) # Returns a new sorted list.
44+
<iter> = reversed(<list>) # Returns reversed iterator.
4545
```
4646

4747
```python
@@ -643,7 +643,6 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary
643643

644644
### Format
645645
```python
646-
>>> from datetime import datetime
647646
>>> dt = datetime.strptime('2015-05-14 23:39:00.00 +0200', '%Y-%m-%d %H:%M:%S.%f %z')
648647
>>> dt.strftime("%A, %dth of %B '%y, %I:%M%p %Z")
649648
"Thursday, 14th of May '15, 11:39PM UTC+02:00"
@@ -653,10 +652,11 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary
653652

654653
### Arithmetics
655654
```python
656-
<D/DT> = <D/DT> ± <TD> # Returned datetime can fall into missing hour.
657-
<TD> = <D/DTn> - <D/DTn> # Returns the difference, ignoring time jumps.
658-
<TD> = <DTa> - <DTa> # Ignores time jumps if they share tzinfo object.
659-
<TD> = <DT_UTC> - <DT_UTC> # Convert DTs to UTC to get the actual delta.
655+
<D/DT> = <D/DT> ± <TD> # Returned datetime can fall into missing hour.
656+
<TD> = <D/DTn> - <D/DTn> # Returns the difference, ignoring time jumps.
657+
<TD> = <DTa> - <DTa> # Ignores time jumps if they share tzinfo object.
658+
<TD> = <TD> * <real> # Also: <TD> = abs(<TD>) and <TD> = <TD> ±% <TD>
659+
<float> = <TD> / <TD> # How many weeks/years there are in TD. Also '//'.
660660
```
661661

662662

index.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226

227227
<body>
228228
<header>
229-
<aside>October 30, 2021</aside>
229+
<aside>November 16, 2021</aside>
230230
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
231231
</header>
232232

@@ -253,16 +253,16 @@
253253
main()
254254
</code></pre></div>
255255

256-
<div><h2 id="list"><a href="#list" name="list">#</a>List</h2><pre><code class="python language-python hljs">&lt;list&gt; = &lt;list&gt;[from_inclusive : to_exclusive : ±step_size]
256+
<div><h2 id="list"><a href="#list" name="list">#</a>List</h2><pre><code class="python language-python hljs">&lt;list&gt; = &lt;list&gt;[&lt;slice&gt;] <span class="hljs-comment"># Or: &lt;list&gt;[from_inclusive : to_exclusive : ±step]</span>
257257
</code></pre></div>
258258

259259
<pre><code class="python language-python hljs">&lt;list&gt;.append(&lt;el&gt;) <span class="hljs-comment"># Or: &lt;list&gt; += [&lt;el&gt;]</span>
260260
&lt;list&gt;.extend(&lt;collection&gt;) <span class="hljs-comment"># Or: &lt;list&gt; += &lt;collection&gt;</span>
261261
</code></pre>
262-
<pre><code class="python language-python hljs">&lt;list&gt;.sort()
263-
&lt;list&gt;.reverse()
264-
&lt;list&gt; = sorted(&lt;collection&gt;)
265-
&lt;iter&gt; = reversed(&lt;list&gt;)
262+
<pre><code class="python language-python hljs">&lt;list&gt;.sort() <span class="hljs-comment"># Sorts in ascending order.</span>
263+
&lt;list&gt;.reverse() <span class="hljs-comment"># Reverses the list in-place.</span>
264+
&lt;list&gt; = sorted(&lt;collection&gt;) <span class="hljs-comment"># Returns a new sorted list.</span>
265+
&lt;iter&gt; = reversed(&lt;list&gt;) <span class="hljs-comment"># Returns reversed iterator.</span>
266266
</code></pre>
267267
<pre><code class="python language-python hljs">sum_of_elements = sum(&lt;collection&gt;)
268268
elementwise_sum = [sum(pair) <span class="hljs-keyword">for</span> pair <span class="hljs-keyword">in</span> zip(list_a, list_b)]
@@ -723,8 +723,7 @@
723723
&lt;float&gt; = &lt;DTa&gt;.timestamp() <span class="hljs-comment"># Seconds since the Epoch, from DTa.</span>
724724
</code></pre></div>
725725

726-
<div><h3 id="format-1">Format</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> datetime <span class="hljs-keyword">import</span> datetime
727-
<span class="hljs-meta">&gt;&gt;&gt; </span>dt = datetime.strptime(<span class="hljs-string">'2015-05-14 23:39:00.00 +0200'</span>, <span class="hljs-string">'%Y-%m-%d %H:%M:%S.%f %z'</span>)
726+
<div><h3 id="format-1">Format</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>dt = datetime.strptime(<span class="hljs-string">'2015-05-14 23:39:00.00 +0200'</span>, <span class="hljs-string">'%Y-%m-%d %H:%M:%S.%f %z'</span>)
728727
<span class="hljs-meta">&gt;&gt;&gt; </span>dt.strftime(<span class="hljs-string">"%A, %dth of %B '%y, %I:%M%p %Z"</span>)
729728
<span class="hljs-string">"Thursday, 14th of May '15, 11:39PM UTC+02:00"</span>
730729
</code></pre></div>
@@ -733,10 +732,11 @@
733732
<li><strong><code class="python hljs"><span class="hljs-string">'%Z'</span></code> only accepts <code class="python hljs"><span class="hljs-string">'UTC/GMT'</span></code> and local timezone's code. <code class="python hljs"><span class="hljs-string">'%z'</span></code> also accepts <code class="python hljs"><span class="hljs-string">'±HH:MM'</span></code>.</strong></li>
734733
<li><strong>For abbreviated weekday and month use <code class="python hljs"><span class="hljs-string">'%a'</span></code> and <code class="python hljs"><span class="hljs-string">'%b'</span></code>.</strong></li>
735734
</ul>
736-
<div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs">&lt;D/DT&gt; = &lt;D/DT&gt; ± &lt;TD&gt; <span class="hljs-comment"># Returned datetime can fall into missing hour.</span>
737-
&lt;TD&gt; = &lt;D/DTn&gt; - &lt;D/DTn&gt; <span class="hljs-comment"># Returns the difference, ignoring time jumps.</span>
738-
&lt;TD&gt; = &lt;DTa&gt; - &lt;DTa&gt; <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span>
739-
&lt;TD&gt; = &lt;DT_UTC&gt; - &lt;DT_UTC&gt; <span class="hljs-comment"># Convert DTs to UTC to get the actual delta.</span>
735+
<div><h3 id="arithmetics">Arithmetics</h3><pre><code class="python language-python apache hljs">&lt;D/DT&gt; = &lt;D/DT&gt; ± &lt;TD&gt; <span class="hljs-comment"># Returned datetime can fall into missing hour.</span>
736+
&lt;TD&gt; = &lt;D/DTn&gt; - &lt;D/DTn&gt; <span class="hljs-comment"># Returns the difference, ignoring time jumps.</span>
737+
&lt;TD&gt; = &lt;DTa&gt; - &lt;DTa&gt; <span class="hljs-comment"># Ignores time jumps if they share tzinfo object.</span>
738+
&lt;TD&gt; = &lt;TD&gt; * &lt;real&gt; <span class="hljs-comment"># Also: &lt;TD&gt; = abs(&lt;TD&gt;) and &lt;TD&gt; = &lt;TD&gt; ±% &lt;TD&gt;</span>
739+
&lt;float&gt; = &lt;TD&gt; / &lt;TD&gt; <span class="hljs-comment"># How many weeks/years there are in TD. Also '//'.</span>
740740
</code></pre></div>
741741

742742
<div><h2 id="arguments"><a href="#arguments" name="arguments">#</a>Arguments</h2><div><h3 id="insidefunctioncall">Inside Function Call</h3><pre><code class="python language-python hljs">&lt;function&gt;(&lt;positional_args&gt;) <span class="hljs-comment"># f(0, 0)</span>
@@ -3020,7 +3020,7 @@
30203020

30213021

30223022
<footer>
3023-
<aside>October 30, 2021</aside>
3023+
<aside>November 16, 2021</aside>
30243024
<a href="https://gto76.github.io" rel="author">Jure Šorn</a>
30253025
</footer>
30263026

0 commit comments

Comments
 (0)