-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa624d7
commit 41c88d1
Showing
23 changed files
with
326 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# Python Sequences | ||
#programming #language #python #datastructure | ||
|
||
Containers: [[aw9b-python-list]]#, [[82os-python-tuples]]#, collections.deque → It has a reference of the object | ||
Flat: string, bytes, array.array → It stores the value of the object itself | ||
- Containers: [[aw9b-python-list]]#, [[82os-python-tuples]]#, collections.deque → It has a reference of the object | ||
- Flat: string, bytes, array.array → It stores the value of the object itself | ||
|
||
Mutable: [[aw9b-python-list]]#, bytearray, array.array, deque | ||
* You can change the sequence itself | ||
Immutable: tuple, string, bytes | ||
* Sequence does not change, and a new one is created | ||
- Mutable: [[aw9b-python-list]]#, bytearray, array.array, deque | ||
* You can change the sequence itself | ||
- Immutable: tuple, string, bytes | ||
* Sequence does not change, and a new one is created | ||
- Operations on sequences: [[5vht-and-with-sequences]]# | ||
- Generation expression: [[0651-genexp]]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# + and * with Sequences | ||
#python #programming #language #efficiency | ||
|
||
- It is the operation `_add_` and `_mul_`. | ||
- `a += b` is the operation `_iadd_`. When it is not implemented, the **fallback** is the `_add_` | ||
- `_iadd_` is the `list.extend()`. Is the same for `bytearray` and `array.array`. | ||
- For `immutable` objects, the `_iadd_` is similar to the `_add_`. | ||
|
||
> [!warning] | ||
> **PERFORMANCE**: Append on `imutable` objects are inefficient | ||
> [!warning] | ||
> **BUG**: Does not put `mutable` objects on `immutable` ones. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# How to learn and understand | ||
#notes #writing #learn #system #organization #method | ||
|
||
- Familiarity is as same of understand. | ||
- If we did not understand we cannot explain something with our words | ||
- Try to search for patterns, detect the distinction and similarities between the concepts and questions | ||
- Reformulate questions and piece of information is more important than to have extensively knowledge base. | ||
- Learn how to manipulate the [[ndec-literature-notes]] and [[wz0b-permanent-notes]], reformulate it, choose the right | ||
words, try to search for gist/patterns. Which is important, what are the important mental models | ||
- Each piece of information is source for other piece of information, make as many connections as possible, which | ||
meaningful context. | ||
- Which aspects are important to write? | ||
- [[8imv-slip-box]] help to create distinctions between concepts and things in general using connections. Use it to | ||
answer the questions you have in mind. | ||
- Some ideas/questions can appear in the middle of research/findings of other ideas, you do not need to answer it right | ||
at the moment, store it on the [[8imv-slip-box]]. | ||
- Write down the note make you argumentation being coherent and be discussed independently of the author. | ||
- Connection is elaboration (Writing, take notes, thinking about connections) | ||
- [[8imv-slip-box]] long-term memory, while brain takes care of creativity | ||
|
||
> [!tip] Quote | ||
> If learning is your goal, cramming is an irrational act | ||
> [!tip] Quote | ||
> what does this all mean for my own research and the questions I think about in my [[8imv-slip-box]]? This is just | ||
> another way of asking: Why did the aspects I wrote down catch my interest? | ||
> [!tip] Quote | ||
> Learning would be not so much about saving information, like on a hard disk, but about building connections and | ||
> bridges between pieces of information to circumvent the inhibition mechanism in the right moment. It is about making | ||
> sure that the right "cues" trigger the right memory, about how we can think strategically to remember the most | ||
> useful information when we need it. | ||
### References | ||
Ahrens, 2017, p82-100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Python Dictionary | ||
#python #datastructure #language #programming | ||
|
||
- [[x4fp-dictcomp]]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Unpacking Sequences and Iterables | ||
#python #programming #datastrcture #language | ||
|
||
- Works with any iterable: [[aw9b-python-list]], [[x4fp-dictcomp]], [[82os-python-tuples]] | ||
- Parallel assignment | ||
|
||
```python | ||
# tuples | ||
>>> lax_coordinates = (33.9425, -118.4080) | ||
>>> latitude, longitude = lax_coordinates | ||
>>> latitude | ||
33.9425 | ||
|
||
>>> T = (20, 8) | ||
>>> divmod(*t) | ||
(2,4) | ||
``` | ||
- Getting the last part | ||
```python | ||
>>> _ , filename = os.path.split('/home/luciano.ssh/id.rsa.pub') | ||
>>> filename | ||
'id_rsa.pub' | ||
``` | ||
|
||
- Getting the excess | ||
```python | ||
>>> a, b, *rest = range(5) | ||
>>> a, b, rest | ||
(0, 1, [2,3,4]) | ||
>>> a, *body, c, d = range(5) | ||
>>> a, body, c, d | ||
(0, [1,2], 3, 4) | ||
>>> fun(*[1,2],3,*range(4,7)) | ||
>>> *range (4), 4 | ||
(0,1,2,3,4) | ||
>>> [*range(4),4] | ||
[0,1,2,3,4] | ||
``` | ||
* Dictionaries | ||
```python | ||
>>> def dump(*kwargs) | ||
return | ||
>>> dump(**{'x':1}, y=2, **{'z':3}) | ||
{'x':1, 'y':2, 'z':3} | ||
>>> {'a':0, **{'x':1}, 'y':2, *{'z':3,'x':4}} # In that case the second x overlap the value of the first one. | ||
``` | ||
|
||
There another way to unpacking things in pythons, it is [[phk2-pattern-matching-or-destructuring]]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
|
||
- [[ndtq-listcomp]]# | ||
- [[j7wj-when-list-is-not-the-best-option-python]]# | ||
- [[nfgb-slicing]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Clojure | ||
#functional #programming #clojure | ||
|
||
- [[vdzq-sequence-abstraction]] | ||
- [[hpky-contagion]] | ||
- [[p09q-ratio]] | ||
- [[qkll-first-rest-and-cons]] | ||
- [[worn-collection-abstraction]] | ||
- [[vdzq-sequence-abstraction]]# | ||
- [[hpky-contagion]]# | ||
- [[p09q-ratio]]# | ||
- [[worn-collection-abstraction]]# | ||
- [[vtpp-bigint-bigdecimal]]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
# Nix | ||
# NixOS | ||
#programming #functional #nix #nixos | ||
|
||
- [[17dv-inherit]] | ||
- [[38pe-lookup-paths]] | ||
- [[6b5l-string-interpolation]] | ||
- [[t58q-nix-language]] | ||
- [[af9g-nix-let-in]] | ||
- [[f8cg-nix-shell-environment]] | ||
- [[j8ti-nixos-package]] | ||
- [[z8de-attribute-set]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
# My Zettelkasten | ||
#root | ||
|
||
This is my Zettelkasten, you will encounter things related to **programming**, **zettelkasten** itself and **note | ||
taking** and etc. | ||
This is my Zettelkasten, you will encounter things related to **programming**, **zettelkasten** itself and **note-taking** and, etc. | ||
|
||
## Programming | ||
|
||
- [[tds4-python]] | ||
- [[ic18-nix]] | ||
- [[b4vt-clojure]] | ||
- [[tds4-python]]# | ||
- [[b4vt-clojure]]# | ||
|
||
## Note Taking | ||
- [[38lz-zettelkasten]] | ||
- [[7t2m-how-to-take-smart-notes]] | ||
- [[tn2j-gtd-getting-things-done]] | ||
## Note-Taking | ||
- [[38lz-zettelkasten]]# | ||
- [[7t2m-how-to-take-smart-notes]]# | ||
- [[tn2j-gtd-getting-things-done]]# | ||
|
||
## | ||
## Linux | ||
- [[ic18-nix]]# | ||
- [[wwgd-shebang]]# | ||
|
||
## Misc | ||
|
||
- [[9ufi-zeigarnik-effect]]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Slicing | ||
#python #programming #datastructure #language | ||
|
||
- `s[a:b:c]`, `a` and `b` are first and second dimension, `c` is the **stride**. | ||
- It is possible to use **slicing** to assign values | ||
|
||
```python | ||
>>> s = 'bicycle' | ||
>>> s[::3] | ||
'bye' | ||
>>> s[::-1] | ||
'elcycle' | ||
>>> s[::-2] | ||
'eccb' #bicycle | ||
>>> l = list(range(10)) | ||
>>> l[3::3] = [11,22] | ||
[0,1,20,11,5,22,9] | ||
``` | ||
|
||
```python | ||
>>> invoice = """ | ||
0.....6.................................40........52...55........ | ||
1909 Pimoroni PiBrella $17.50 3 $52.50 | ||
1489 6mm Tactile Switch x20 $4.95 2 $9.90 | ||
1510 Panavise Jr. - PV-201 $28.00 1 $28.00 | ||
1601 PiTFT Mini Kit 320x240 $34.95 1 $34.95 | ||
""" | ||
|
||
>>> SKU = slice(0, 6) | ||
>>> DESCRIPTION = slice(6, 40) | ||
>>> UNIT_PRICE = slice(40, 52) | ||
>>> QUANTITY = slice(52, 55) | ||
>>> ITEM_TOTAL = slice(55, None) | ||
>>> line_items = invoice.split('\n')[2:] | ||
>>> for item in line_items: | ||
print(item[UNIT_PRICE], item[DESCRIPTION]) | ||
$17.50 imoroni PiBrella | ||
$4.95 mm Tactile Switch x20 | ||
$28.00 anavise Jr. - PV-201 | ||
$34.95 iTFT Mini Kit 320x240 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Pattern Matching or Destructuring | ||
#python #programming #datastructure #language | ||
|
||
- Destructuring like `Clojure` and `Scala` | ||
- Pattern match are way to `match/case` things like `if/else` conditional. | ||
- For `dict` the `order` of `key` does **not matter** and are possible to have `partial`. Which are different from | ||
[[4dyw-python-sequences]]. | ||
|
||
```python | ||
# Dictionary | ||
# tag::DICT_MATCH[] | ||
def get_creators(record: dict) -> list: | ||
match record: | ||
case {'type': 'book', 'api': 2, 'authors': [*names]}: # <1> | ||
return names | ||
case {'type': 'book', 'api': 1, 'author': name}: # <2> | ||
return [name] | ||
case {'type': 'book'}: # <3> | ||
raise ValueError(f"Invalid 'book' record: {record!r}") | ||
case {'type': 'movie', 'director': name}: # <4> | ||
return [name] | ||
case _: # <5> | ||
raise ValueError(f'Invalid record: {record!r}') | ||
# end::DICT_MATCH[] | ||
|
||
>>> b1 = dict(api=1, author='Douglas Hofstadter', | ||
... type='book', title='Gödel, Escher, Bach') | ||
>>> get_creators(b1) | ||
['Douglas Hofstadter'] | ||
>>> from collections import OrderedDict | ||
>>> b2 = OrderedDict(api=2, type='book', | ||
... title='Python in a Nutshell', | ||
... authors='Martelli Ravenscroft Holden'.split()) | ||
>>> get_creators(b2) | ||
['Martelli', 'Ravenscroft', 'Holden'] | ||
>>> get_creators({'type': 'book', 'pages': 770}) | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Invalid 'book' record: {'type': 'book', 'pages': 770} | ||
>>> get_creators('Spam, spam, spam') | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Invalid record: 'Spam, spam, spam' | ||
# end::DICT_MATCH_TEST[] | ||
""" | ||
``` | ||
```python | ||
# Dictionary partial with destructuring | ||
>>> food = dict (category='ice cream', flavor='vanilla', cost=199) | ||
>>> match food: | ||
case {'category': 'ice cream', **details}: # Details capture the rest of the values | ||
print(f'Ice cream details: {details}') | ||
``` | ||
## Sequence Pattern | ||
- Sequence pattern => () = [] | ||
- str, bytes = bytearray are treated atomic, they need to be converted into tuple or list | ||
- The symbol `_` can be used multiple times on the **pattern matching** | ||
- We can use classes or `str`, `float` or `classes` to runtime check the type of pattern match | ||
```python | ||
case [str(name), _, _, (float(lat), float(lon)), as coord] lon <= 0 # Runtime check with float and str | ||
``` | ||
- The "lon ≤ 0" part is known as **guard rail**. They are evaluated only if match is matched. | ||
```python | ||
case ['define', Symbol as name, value_exp] # Test if name is Symbol | ||
``` | ||
```python | ||
metro_areas = [ | ||
('Tokyo', 'JP', 36.933, (35.689722, 139.691667)), | ||
('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)), | ||
('Mexico City', 'MX', 20.142, (19.433333, -99.133333)), | ||
('New York-Newark', 'US', 20.104, (40.808611, -74.020386)), | ||
('São Paulo', 'BR', 19.649, (-23.547778, -46.635833)), | ||
] | ||
def main(): | ||
print(f'{"":15} | {"latitude":>9} | {"longitude":>9}') | ||
for record in metro_areas: | ||
match record: | ||
case [name, _, _, (lat, lon)] if lon <= 0: | ||
print(f'{name:15} | {lat:9.4f} | {lon:9.4f}') | ||
main() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.