Code for the last project of C0ursera:Python Data Structure

Jawad Abbasi
Jul 28, 2023

name =’mbox-short.txt’
open_file=open(name)
dicto =dict()
for lines in open_file:
strip_lines =lines.rstrip()
if strip_lines.startswith(‘From’):
#print(strip_lines)

split_lines=strip_lines.split()
sorting_lines =sorted(split_lines)
#print(sorting_lines)
if len(sorting_lines) > 2:
#print(sorting_lines)
first_word =sorting_lines[0]
sec_split =first_word.split(‘:’)
#print(sorted(sec_split))
if sec_split[0] in dicto:
dicto[sec_split[0]]+= 1
else:
dicto[sec_split[0]] = 1

p =dicto
for i,j in sorted(dicto.items()):
print(i,j)

--

--