NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
import ctypes | |
import enum | |
# | |
# Prerequisits: | |
# ------------- | |
# If you are using Python < 3.4 run `pip install enum34`. | |
# | |
# Problem Definition | |
# ------------------ |
__author__ = 'leonmax' | |
import asyncio | |
from asyncio import (coroutine, subprocess) | |
import sys | |
import logging | |
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
logging.basicConfig(level=logging.INFO, format=FORMAT) |
NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.
If you are not into long explanations, see [Paolo Bergantino’s answer][2].
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!