-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverse-easy.py
53 lines (44 loc) · 1 KB
/
reverse-easy.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
51
52
53
from collections import deque
def reverse_string(input_str):
stack = deque()
reversed = []
for ele in input_str:
stack.append(ele)
for _ in range(len(input_str)):
reversed += stack.pop()
return ''.join(reversed)
def main():
print("Reverse: " + str(reverse_string("akash")))
main()
# read the string filename
from collections import OrderedDict
filename = input()
# print(filename)
with open(filename) as fp:
fp = fp.read()
# print(fp)
res = {}
for line in fp.split("\n"):
# print(line)
# print(line.strip().split(' ')[0])
host = line.strip().split(' ')[0]
if len(host)==0:
continue
if res.get(host) is None:
res[host] = 1
else:
res[host] += 1
# print(res)
filename = "records_"+filename
# print(filename)
fp = open(filename, "w")
sor = res.keys()
sor = sorted(sor)
# print(sor)
for k in sor:
fp.write(k+" "+str(res[k]))
# fp.write(k)
# fp.write(res[k])
print(k, res[k])
fp.close()
# return filename