0% found this document useful (0 votes)
2 views2 pages

Dictionary Processing

The Python program processes an email log to extract usernames and their associated domains, converting usernames to lowercase. It counts the number of unique domains for each username and outputs the results. The program uses functions to handle character conversion and data processing.

Uploaded by

velshakthi406
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Dictionary Processing

The Python program processes an email log to extract usernames and their associated domains, converting usernames to lowercase. It counts the number of unique domains for each username and outputs the results. The program uses functions to handle character conversion and data processing.

Uploaded by

velshakthi406
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON PROGRAM :

def to_lower(ch):

if 'A' <= ch <= 'Z':

return chr(ord(ch) + 32)

return ch

def process_log(log):

data = {}

i=0

n = len(log)

while i < n:

username = ""

domain = ""

while i < n and log[i] != '+':

username += to_lower(log[i])

i += 1

while i < n and log[i] != '@':

i += 1

i += 1

while i < n and log[i] != ' ':

domain += to_lower(log[i])

i += 1

i += 1

if username not in data:

data[username] = domain

else:
if domain not in data[username]:

data[username] += "," + domain

return data

def count_domains(data):

result = {}

for user in data:

count = 1

for ch in data[user]:

if ch == ',':

count += 1

result[user] = count

return result

log = input("Enter email log: ")

domain_data = process_log(log)

final_output = count_domains(domain_data)

for user in final_output:

print(user, final_output[user])

INPUT AND OUTPUT:

You might also like