Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| # From the book, effective python 2nd edition item 37 | |
| from collections import defaultdict | |
| from dataclasses import dataclass, field | |
| from typing import List, Dict | |
| @dataclass | |
| class Grade: | |
| weight: int |
| #!/bin/bash | |
| # ~/.bashrc: executed by bash(1) for non-login shells. | |
| # kevin gallagher (@ageis) <[email protected]> | |
| # normally I divide this into separate files: .bashrc, .bash_profile, .bash_aliases and .bash_functions (also .bash_logout), but it's all concatenated here. | |
| ulimit -s unlimited | |
| export MYUID=$(id -u) | |
| export USER="$(id -un)" | |
| if [[ "$TILIX_ID" ]] || [[ "$VTE_VERSION" ]]; then |
| # coding: utf8 | |
| languages = [ | |
| ('aa', 'Afar'), | |
| ('ab', 'Abkhazian'), | |
| ('af', 'Afrikaans'), | |
| ('ak', 'Akan'), | |
| ('sq', 'Albanian'), | |
| ('am', 'Amharic'), | |
| ('ar', 'Arabic'), |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!