Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def tobytes(k, f):
- if f == 'B':
- return int(k)
- if f == 'KB':
- return int(k) * 1024
- if f == 'MB':
- return int(k) * 1024 * 1024
- if f == 'GB':
- return int(k) * 1024 * 1024 * 1024
- if f == 'TB':
- return int(k) * 1024 * 1024 * 1024 * 1024
- def st(x):
- return x[0]
- def tomax(x):
- frs = ['B', 'KB', 'MB', 'GB', 'TB']
- k = 0
- t = x
- while t >= 1024:
- t = t / 1024
- k += 1
- if frs[k] == 'TB':
- t = t * 1024
- k -= 1
- return str(round(t)) + ' ' + frs[k]
- f = open('input.txt', 'r', encoding='utf-8')
- s = []
- ty = []
- sz = []
- for i in f:
- s.append(i.strip('\n').split(' '))
- f.close()
- for i in range(len(s)):
- fr = s[i][0].split('.')[1]
- if fr not in ty:
- sz.append(0)
- ty.append(fr)
- ty.sort()
- for i in range(len(s)):
- fr = s[i][0].split('.')[1]
- sz[ty.index(fr)] = sz[ty.index(fr)] + tobytes(s[i][1], s[i][2])
- s.sort(key=st)
- f = open('output.txt', 'w', encoding='utf-8')
- for i in range(len(ty)):
- for ii in range(len(s)):
- if s[ii][0].split('.')[1] == ty[i]:
- f.write(s[ii][0] + '\n')
- f.write('----------\n')
- f.write('Summary: ' + tomax(sz[i]) + '\n\n')
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement