-
Notifications
You must be signed in to change notification settings - Fork 0
/
excercises.py
44 lines (38 loc) · 1.11 KB
/
excercises.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def palindrome(string):
for i in range (0, len(string)/2):
if string[i] is not string[-i-1]:
return False
break
else:
return True
def pangram(sentence):
for i in "qwertyuiopasdfghjklzxcvbnm":
if i not in sentence.lower():
return False
return True
def letter_freq(string):
d = dict()
for i in string.lower():
if i not in d.keys():
d[i] = 0
else:
pass
d[i] = d[i]+1
return d
def evaluate_postfix(expression):
stack = []
for i in expression:
if i.isdigit():
stack.append(int(i))
elif i is "*":
stack = stack[:-2] + [stack[-1] * stack[-2]]
elif i is "+":
stack = stack[:-2] + [stack[-1] + stack[-2]]
elif i is "-":
stack = stack[:-2] + [stack[-1] - stack[-2]]
elif i is "/":
stack = stack[:-2] + [stack[-1] / stack[-2]]
else:
print "Unable to evaluate postfix"
return False
return stack[0]