Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# author: Rolando Espinoza La fuente | |
from scrapy.conf import settings | |
from scrapy.core import signals | |
from scrapy.core.manager import scrapymanager | |
from scrapy.item import Item, Field | |
from scrapy.selector import HtmlXPathSelector | |
from scrapy.spider import BaseSpider |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
This page is designed to give you a list of concrete examples demonstrating idiomatic (Pythonic) code.
Many of the examples were taken from the following resources:
FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.
{ | |
"7 Pot Brain Strain Red Pepper": "Capsicum chinense", | |
"7 Pot Bubble Gum Pepper": "Capsicum chinense", | |
"7 Pot Pepper Barrackpore": "Capsicum chinense", | |
"7 Pot Pepper Brain Strain Yellow": "Capsicum chinense", | |
"7 Pot Pepper Orange": "Capsicum chinense", | |
"7 Pot Pepper Yellow": "Capsicum chinense", | |
"7 Pot Pink Pepper": "Capsicum chinense", | |
"7 Pot Rust Pepper": "Capsicum chinense", | |
"Abe Lincoln Tomato": "Solanum lycopersicum", |