E
E
ezbooz2021-07-28 21:07:59
Python
ezbooz, 2021-07-28 21:07:59

How can I collect domain statistics in a file?

There is a file that contains the lines

[email protected]:password
[email protected]:password
[email protected]:password

How can I collect statistics about domains and display them in the format
domen - сколько всего в файле

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dmshar, 2021-07-28
@ezbooz

Well, if you give us a list instead of a file, then we will assume that you can create the corresponding list from the file. Let this be the lines list in the example below.
And then - everything is simple:

import re
lines=["[email protected]:password","[email protected]:password","[email protected]:password",
       "[email protected]:password","[email protected]:password", "[email protected]:password",
       "[email protected]:password","[email protected]:password"]
st_list=[]
for ln in lines:
    st=re.findall(r"\@(.*?)\:", ln)
    st_list.append(st[0])
st_count = {i: st_list.count(i) for i in st_list}
print (st_count)

Result:
{'domen1': 1, 'domen2': 3, 'domen3': 2, 'domen4': 2}

V
Vindicar, 2021-07-28
@Vindicar

1. re module
2. collections.Counter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question