Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

polish notation python

#! /usr/bin/env python
from collections import deque
def parse(tokens):
    token=tokens.popleft()
    if token=='+':
            return parse(tokens)+parse(tokens)
    elif token=='-':
            return parse(tokens)-parse(tokens)
    elif token=='*':
            return parse(tokens)*parse(tokens)
    elif token=='/':
            return parse(tokens)/parse(tokens)
    else:
            # must be just a number
            return int(token)


if __name__=='__main__':
        expression="+ 2 2"
        print parse(deque(expression.split()))
Comment

PREVIOUS NEXT
Code Example
Python :: python reduce 
Python :: pandas apply check for string length in column 
Python :: pandas remove repeated index 
Python :: python remove duplicates 
Python :: sqlite operational error no such column 
Python :: seaborn distplot 
Python :: python urlparse get domain 
Python :: python runserver port 
Python :: df.fillna(-999,inplace=True) 
Python :: csv file sort python 
Python :: hash with python 
Python :: download image from url 
Python :: python *x 
Python :: argmax implementation 
Python :: python dropbox 
Python :: bubble sort with code optimization 
Python :: map python 3 
Python :: download folder collab 
Python :: add list to end of list python 
Python :: reorder list python 
Python :: add option in python script 
Python :: python for continue 
Python :: how to add subtitle to matplotlib 
Python :: tkinter canvas text size 
Python :: python .findall 
Python :: how to go up levels in path python 
Python :: randomly pick a value in the list 
Python :: fernet generate key from password 
Python :: python undefined 
Python :: getting input in python 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =