@@ -204,7 +204,7 @@ <h1 id="comprehensivepythoncheatsheet">Comprehensive Python Cheatsheet</h1>
204
204
205
205
< br > < h2 id ="toc "> < a href ="#toc " name ="toc "> #</ a > Contents</ h2 >
206
206
< pre > < code class ="hljs bash "> < strong > ToC</ strong > = {
207
- < strong > < span class ="hljs-string "> < span class ="hljs-string "> '1. Collections'</ span > </ span > </ strong > : [< a href ="#list "> List</ a > , < a href ="#dictionary "> Dict</ a > , < a href ="#set "> Set</ a > , < a href ="#range " > Range </ a > , < a href ="#enumerate " > Enumerate </ a > , < a href ="#namedtuple " > Namedtuple </ a > , < a href ="#iterator "> Iterator</ a > , < a href ="#generator "> Generator</ a > ],
207
+ < strong > < span class ="hljs-string "> < span class ="hljs-string "> '1. Collections'</ span > </ span > </ strong > : [< a href ="#list "> List</ a > , < a href ="#dictionary "> Dict</ a > , < a href ="#set "> Set</ a > , < a href ="#tuple " > Tuple </ a > , < a href ="#range " > Range </ a > , < a href ="#enumerate " > Enumerate </ a > , < a href ="#iterator "> Iterator</ a > , < a href ="#generator "> Generator</ a > ],
208
208
< strong > < span class ="hljs-string "> < span class ="hljs-string "> '2. Types'</ span > </ span > </ strong > : [< a href ="#type "> Type</ a > , < a href ="#string "> String</ a > , < a href ="#regex "> Regex</ a > , < a href ="#format "> Format</ a > , < a href ="#numbers "> Numbers</ a > , < a href ="#combinatorics "> Combinatorics</ a > , < a href ="#datetime "> Datetime</ a > ],
209
209
< strong > < span class ="hljs-string "> < span class ="hljs-string "> '3. Syntax'</ span > </ span > </ strong > : [< a href ="#arguments "> Args</ a > , < a href ="#inline "> Inline</ a > , < a href ="#closure "> Closure</ a > , < a href ="#decorator "> Decorator</ a > , < a href ="#class "> Class</ a > , < a href ="#ducktypes "> Duck_Types</ a > , < a href ="#enum "> Enum</ a > , < a href ="#exceptions "> Exceptions</ a > ],
210
210
< strong > < span class ="hljs-string "> < span class ="hljs-string "> '4. System'</ span > </ span > </ strong > : [< a href ="#print "> Print</ a > , < a href ="#input "> Input</ a > , < a href ="#commandlinearguments "> Command_Line_Arguments</ a > , < a href ="#open "> Open</ a > , < a href ="#path "> Path</ a > , < a href ="#commandexecution "> Command_Execution</ a > ],
@@ -286,27 +286,21 @@ <h2 id="set"><a href="#set" name="set">#</a>Set</h2>
286
286
< pre > < code class ="python language-python hljs "> <set>.remove(<el>) < span class ="hljs-comment "> # Raises KeyError.</ span >
287
287
<set>.discard(<el>) < span class ="hljs-comment "> # Doesn't raise an error.</ span >
288
288
</ code > </ pre >
289
- < h3 id ="frozenset "> Frozenset</ h3 >
290
- < h4 id ="ishashablemeaningitcanbeusedasakeyinadictionaryorasanelementinaset "> Is hashable, meaning it can be used as a key in a dictionary or as an element in a set.</ h4 >
289
+ < h3 id ="frozenset "> Frozen Set</ h3 >
290
+ < ul >
291
+ < li > < strong > Frozen set is immutable and hashable set.</ strong > </ li >
292
+ < li > < strong > It can be used as a key in a dictionary or as an element in a set.</ strong > </ li >
293
+ </ ul >
291
294
< pre > < code class ="python language-python hljs "> <frozenset> = frozenset(<collection>)
292
295
</ code > </ pre >
293
- < h2 id ="range "> < a href ="#range " name ="range "> #</ a > Range</ h2 >
294
- < pre > < code class ="python language-python hljs "> <range> = range(to_exclusive)
295
- <range> = range(from_inclusive, to_exclusive)
296
- <range> = range(from_inclusive, to_exclusive, ±step_size)
297
- </ code > </ pre >
298
- < pre > < code class ="python language-python hljs "> from_inclusive = <range>.start
299
- to_exclusive = <range>.stop
296
+ < h2 id ="tuple "> < a href ="#tuple " name ="tuple "> #</ a > Tuple</ h2 >
297
+ < p > < strong > Tuple is immutable and hashable list.</ strong > </ p >
298
+ < pre > < code class ="python language-python hljs "> <tuple> = ()
299
+ <tuple> = (<el>, )
300
+ <tuple> = (<el_1>, <el_2>, ...)
300
301
</ code > </ pre >
301
- < h2 id ="enumerate "> < a href ="#enumerate " name ="enumerate "> #</ a > Enumerate</ h2 >
302
- < pre > < code class ="python language-python hljs "> < span class ="hljs-keyword "> for</ span > i, el < span class ="hljs-keyword "> in</ span > enumerate(<collection> [, i_start]):
303
- ...
304
- </ code > </ pre >
305
- < h2 id ="namedtuple "> < a href ="#namedtuple " name ="namedtuple "> #</ a > Named Tuple</ h2 >
306
- < ul >
307
- < li > < strong > Tuple is an immutable and hashable list.</ strong > </ li >
308
- < li > < strong > Named tuple is its subclass with named elements.</ strong > </ li >
309
- </ ul >
302
+ < h3 id ="namedtuple "> Named Tuple</ h3 >
303
+ < p > < strong > Named tuple is tuple's subclass with named elements.</ strong > </ p >
310
304
< pre > < code class ="python language-python hljs "> < span class ="hljs-meta "> >>> </ span > < span class ="hljs-keyword "> from</ span > collections < span class ="hljs-keyword "> import</ span > namedtuple
311
305
< span class ="hljs-meta "> >>> </ span > Point = namedtuple(< span class ="hljs-string "> 'Point'</ span > , < span class ="hljs-string "> 'x y'</ span > )
312
306
< span class ="hljs-meta "> >>> </ span > p = Point(< span class ="hljs-number "> 1</ span > , y=< span class ="hljs-number "> 2</ span > )
@@ -320,6 +314,18 @@ <h2 id="namedtuple"><a href="#namedtuple" name="namedtuple">#</a>Named Tuple</h2
320
314
< span class ="hljs-meta "> >>> </ span > p._fields < span class ="hljs-comment "> # Or: Point._fields</ span >
321
315
(< span class ="hljs-string "> 'x'</ span > , < span class ="hljs-string "> 'y'</ span > )
322
316
</ code > </ pre >
317
+ < h2 id ="range "> < a href ="#range " name ="range "> #</ a > Range</ h2 >
318
+ < pre > < code class ="python language-python hljs "> <range> = range(to_exclusive)
319
+ <range> = range(from_inclusive, to_exclusive)
320
+ <range> = range(from_inclusive, to_exclusive, ±step_size)
321
+ </ code > </ pre >
322
+ < pre > < code class ="python language-python hljs "> from_inclusive = <range>.start
323
+ to_exclusive = <range>.stop
324
+ </ code > </ pre >
325
+ < h2 id ="enumerate "> < a href ="#enumerate " name ="enumerate "> #</ a > Enumerate</ h2 >
326
+ < pre > < code class ="python language-python hljs "> < span class ="hljs-keyword "> for</ span > i, el < span class ="hljs-keyword "> in</ span > enumerate(<collection> [, i_start]):
327
+ ...
328
+ </ code > </ pre >
323
329
< h2 id ="iterator "> < a href ="#iterator " name ="iterator "> #</ a > Iterator</ h2 >
324
330
< pre > < code class ="python language-python hljs "> < span class ="hljs-keyword "> from</ span > itertools < span class ="hljs-keyword "> import</ span > count, repeat, cycle, chain, islice
325
331
</ code > </ pre >
0 commit comments