-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3.py
53 lines (36 loc) · 847 Bytes
/
3.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
45
46
47
48
49
50
__author__ = 'gongzhi'
'''
url = http://www.pythonchallenge.com/pc/def/ocr.html
view source and save the mess string in a txt file.
'''
data = {}
import sys
def char_count(input_string):
for i in range(len(input_string)):
char = input_string[i]
if (data.has_key(char) == False):
data[char] = 1
else:
data[char] += 1
def get_smallest_count():
small_value = sys.maxint
for i in dict(data).values():
if small_value > i:
small_value = i
return small_value
def get_smallest_list(small_value):
res = []
for (k, v) in dict(data).items():
if v == small_value:
res += k
return res
if __name__ == "__main__":
print "question 3"
mess = open("3.txt").read()
char_count(mess)
res = get_smallest_list(get_smallest_count())
ret = ''
for i in range(len(mess)):
if mess[i] in res:
ret += mess[i]
print ret