Skip to content

Instantly share code, notes, and snippets.

View gardyna's full-sized avatar

Dagur Arinbjörn Daníelsson gardyna

View GitHub Profile
@gardyna
gardyna / reverse_polish_evaluator.py
Last active September 28, 2019 06:20 — forked from viebel/reverse_polish_evaluator.py
reverse polish evaluator in python
# This example assumes binary operators, but this is easy to extend.
# Comes from this excellent article: http://blog.reverberate.org/2013/07/ll-and-lr-parsing-demystified.html
ops = {
"+": (lambda a, b: a + b),
"-": (lambda a, b: a - b),
"*": (lambda a, b: a * b),
"/": (lambda a, b: a / b)
}
def eval(expression):
// BynaryTree.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// all code copy pasted in haste
#list construction
my_dict = dict()
for l in lists:
for name in lst:
my_dict[name] = my_dict.get(name, 0)+1
# dict.get(key, default) return value associated with key or default if none is found