2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by ZZucker
0

The trick is to split your email data into a list of lines first, and the split each line into user, provider at the @ character. For example:

email = """\
manolis@gmail.com
giannis@gmail.com
kostas@yahoo.com
eirini@yahoo.com
ssss@aol.com
wertza@yahoo.gr
xristhanthi@gmail.com
"""

# split into list of lines
lines = email.split()

provider_freq = {}
for item in lines:
    # split each line item at the @ character
    user, provider = item.split('@')
    #print user, provider  # test
    # build the dictionary
    count = provider_freq.get(provider, 0)
    provider_freq[provider] = count + 1
    
print provider_freq

"""
my output -->
{'yahoo.com': 2, 'aol.com': 1, 'gmail.com': 3, 'yahoo.gr': 1}
"""
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.