Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| #!/bin/sh | |
| DESC="Jenkins CI Server" | |
| NAME=jenkins | |
| PIDFILE=/var/run/$NAME.pid | |
| RUN_AS=jenkins | |
| COMMAND=/usr/bin/java -- -jar /home/jenkins/jenkins.war | |
| d_start() { | |
| start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --exec $COMMAND |
| kill $(ps aux | grep "python rr"| sed "s|[a-zA-Z=:/+\.\-]||g" | sed "s/\([0-9][0-9]*\)\(\s\s*[0-9][0-9]*\)*/\1/g") |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| ############# | |
| # INFO # | |
| ############# | |
| Allgemein: | |
| ========== | |
| - NGN: Konvergenz aller Netzwerke zu IP-Netzwerken um Kosten zu sparen | |
| - PBX: Router für Telefon-Netzwerke | |
| - Telepathy (http://telepathy.freedesktop.org) communications framework | |
| - Sofia-SIP: Telepathy Plugin for SIP connection management | |
| - NoSQL DBs: Hadoop, HBase, Cassandra, Hypertable, Cloudera, MongoDB, CouchDB |
| #Input data: | |
| calls = [ | |
| ( 'n1', 'n2', 'success' ), | |
| ( 'n1', 'n3', 'failed' ), | |
| ( 'n1', 'n2', 'failed' ), | |
| ( 'n2', 'n1', 'failed' ) | |
| ] | |
| def connectivity(calls): | |
| """given a list of calls in the form of [(caller, callee, 'success' or 'failed'),...] |
| setValue(AB) :-> A'='B /*store the relation A=>B somewhere, for example a dict() or a Hashmap*/ | |
| getValue(A) :-> B /*load and return it from the storage*/ | |
| Operation(aBC) :-> B+C, a='+' | |
| :-> B-C, a='-' | |
| :-> B*C, a='*' | |
| :-> B/C, a='/' | |
| Newline(a) :-> a; a in [\n|\r|\n\r] | |
| Letter(a) :-> a; a in [a-zA-Z] | |
| DigitNoZero(a) :-> a; a in [1-9] | |
| Digit(a) :-> a; a = 0 |
| #Words | |
| <Inner_Block> ::= <Block_Start><Block><Block_End> | |
| <Block>* ::= <Expression>(<Exp_Sep><Expression>)* | |
| <Expression> ::= <Sum>|<Assignment> | |
| <Assignment> ::= <Name><Assign_Op><Inner_Block> | |
| <Sum> ::= <Difference>(<Add_Op><Difference>)* | |
| <Difference> ::= <Product>(<Sub_Op><Product>)* | |
| <Product> ::= <Quotient>(<Mul_Op><Quotient>)* | |
| <Quotient> ::= <Term>(<Div_Op><Term>)* | |
| <Term> ::= <Number>|<Call>|<Inner_Block> |
| class Hausaufgabe { | |
| public static int anzahl(String vieleZeichen, String b) { | |
| if((vieleZeichen == null) || (vieleZeichen.isEqual("")) return 0; | |
| String w = vieleZeichen.subString(0,vieleZeichen.length()-2); | |
| String a = "" + vieleZeichen.getChar(vieleZeichen.length()-1); | |
| if(a.isEqual(b)) return anzahl(w, b)+1; | |
| if(!a.isEqual(b)) return anzahl(w,b); | |
| } | |
| } |
| import warnings | |
| STATE_CLEAR = 1 | |
| STATE_VAR = 2 | |
| STATE_SPECIAL = 3 | |
| VAR_ALLOWED_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
| # special chars make it more usable for non programmers, who probably never heard about \n and so on | |
| # more can and will be added later on | |
| special_char_map = {'NEWLINE' : '\n'} |
| >>> parse_input(input, gramar) | |
| { | |
| 'text': '\xe4\xbd\xa0\xe5\xa5\xbd,ni3hao3,hello\n\xe8\xb0\xa2\xe8\xb0\xa2,xie4xie0,thanks\n\xe5\xaf\xb9\xe4\xb8\x8d\xe8\xb5\xb7,dui4bu0qi3,sorry', | |
| 'type': 'InputText', | |
| 'children': [ | |
| { | |
| 'text': '\xe4\xbd\xa0\xe5\xa5\xbd,ni3hao3,hello\n', | |
| 'type': 'TextBlock', | |
| 'children': [ | |
| {'text': '\xe4\xbd\xa0\xe5\xa5\xbd', 'type': 'A', 'children': []}, |