Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| class AdjacencyMatrix[T: Manifest](size: Int) { | |
| // initialize it | |
| // (It's in column vector format) | |
| val matrix = Array.ofDim[T](size, size) | |
| // helper functions | |
| // takes a list of 3-tuples in the form: (from, to, weight) | |
| def setConnections(connections: List[(Int, Int, T)]) = { | |
| for (x <- connections) { | |
| // make matrix[to][from] = weight |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| #!/bin/sh | |
| # | |
| # Too many crusty old git branches? Run this to find likely candidates for deletion | |
| # It lists all the remote branches and sorts them by age. | |
| # | |
| # Folks at pivotal shared this with me | |
| # | |
| #$ . show-remote-branch-info.sh | |
| # 2012-05-04 09:42:29 -0700 4 minutes ago Ted & Bill \torigin/hey_Bill |
| (use 'clojure.test) | |
| (deftest tracing-paths | |
| (testing "trace-paths" | |
| (is (= (trace-paths {:a nil} :a) | |
| [[:a]])) | |
| (is (= (trace-paths {:a #{:b} | |
| :b nil} :a) |
| # Python logger in AWS Lambda has a preset format. To change the format of the logging statement, | |
| # remove the logging handler & add a new handler with the required format | |
| import logging | |
| import sys | |
| def setup_logging(): | |
| logger = logging.getLogger() | |
| for h in logger.handlers: | |
| logger.removeHandler(h) |
| # -*- coding: utf-8 -*- | |
| # /var/runtime/awslambda/bootstrap.py | |
| """ | |
| aws_lambda.bootstrap.py | |
| Amazon Lambda | |
| Copyright (c) 2013 Amazon. All rights reserved. | |
| Lambda runtime implemention | |
| """ |
| #!/usr/bin/env python3 | |
| def cli(): | |
| @command | |
| def hello(*args): | |
| cmd('echo', 'Hello', *args) | |