Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| from hypothesis import given, settings | |
| from hypothesis.strategies import lists, sampled_from | |
| def new_state(): | |
| return {'big': 0, 'small': 0} | |
| def invariants(state): | |
| return (0 <= state['small'] <= 3 and | |
| 0 <= state['big'] <= 5) |
| import binascii | |
| import struct | |
| class Punk(object): | |
| """Full blog post about hiding data within PNG files here: | |
| http://blog.brian.jp/python/png/2016/07/07/file-fun-with-pyhon.html | |
| Example use case: |
| require 'digest/md5' | |
| def gfm(text) | |
| # Extract pre blocks | |
| extractions = {} | |
| text.gsub!(%r{<pre>.*?</pre>}m) do |match| | |
| md5 = Digest::MD5.hexdigest(match) | |
| extractions[md5] = match | |
| "{gfm-extraction-#{md5}}" | |
| end |
| var parser = document.createElement('a'); | |
| parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
| parser.protocol; // => "http:" | |
| parser.hostname; // => "example.com" | |
| parser.port; // => "3000" | |
| parser.pathname; // => "/pathname/" | |
| parser.search; // => "?search=test" | |
| parser.hash; // => "#hash" | |
| parser.host; // => "example.com:3000" |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!