Login Register






Password count duplicate and sort. filter_list
Author
Message
Password count duplicate and sort. #1
New member and love python xD

Code:
from collections import defaultdict from tqdm import tqdm class Counter(): def __init__(self, input_file): self.mp_dict = defaultdict(int) self.input_file = input_file self.sorted_dict = None def run(self): print('Sorting') with open(self.input_file, 'r+') as f: for line in tqdm(f.readlines()): if len(line) > 1: if line.strip() in self.mp_dict: self.mp_dict[line.strip()] += 1 elif line.strip() not in self.mp_dict: self.mp_dict[line.strip()] = 1 self.sorted_dict = sorted(self.mp_dict.items(), key=lambda x: x[1], reverse=True) self.write_result() def write_result(self): print('Writing result') with open(self.input_file + '_result.txt', 'a+') as r: for item in tqdm(self.sorted_dict): r.write(item[0] + '\n') p = Counter(r'/home/username/password.txt').run() print('Done!!!')

Reply

RE: Password count duplicate and sort. #2
Thanks for the share although, you don't drop down any issues. 1 issue I will see is, the directory or the path file. You love "python" but, the file won't read unless it's given the correct path.

Reply

RE: Password count duplicate and sort. #3
(07-09-2018, 09:51 AM)Mimiakira Wrote: Thanks for the share although, you don't drop down any issues. 1 issue I will see is, the directory or the path file. You love "python" but, the file won't read unless it's given the correct path.

Find the file path is very easy bro.

Reply

RE: Password count duplicate and sort. #4
(07-09-2018, 09:51 AM)Mimiakira Wrote: the file won't read unless it's given the correct path.

Correct me If I'm wrong, but given ever user has their preferred directory, wouldn't you simply select It?
[Image: AD83g1A.png]

Reply

RE: Password count duplicate and sort. #5
(07-09-2018, 11:28 AM)mothered Wrote:
(07-09-2018, 09:51 AM)Mimiakira Wrote: the file won't read unless it's given the correct path.

Correct me If I'm wrong, but given ever user has their preferred directory, wouldn't you simply select It?

I'll give it a try on my mac.

Reply

RE: Password count duplicate and sort. #6
(07-09-2018, 12:10 PM)Mimiakira Wrote:
(07-09-2018, 11:28 AM)mothered Wrote:
(07-09-2018, 09:51 AM)Mimiakira Wrote: the file won't read unless it's given the correct path.

Correct me If I'm wrong, but given ever user has their preferred directory, wouldn't you simply select It?

I'll give it a try on my mac.

Thank you.

If you get a moment, I'd be Interested In reading the results.
[Image: AD83g1A.png]

Reply

RE: Password count duplicate and sort. #7
Here is there error -

Traceback (most recent call last):
File "test.py", line 2, in <module>
from tqdm import tqdm
ImportError: No module named tqdm

Reply

RE: Password count duplicate and sort. #8
if i'm not mistaken you need to download tqdm it looks to me like a library in java, but i'm not sure, i don't know python.


Everyone should learn how to code, it teaches you how to think.

You don't have to be a Genius to know how to code you just need to be determined.

The computer is incredibly fast, accurate, and stupid; man is unbelievably slow, inaccurate, and brilliant; together they are powerful beyond imagination.

Reply

RE: Password count duplicate and sort. #9
(07-09-2018, 01:26 PM)Mimiakira Wrote: Here is there error -

Traceback (most recent call last):
 File "test.py", line 2, in <module>
   from tqdm import tqdm
ImportError: No module named tqdm

you need to install tqdm module. "pip install tqdm"

Reply

RE: Password count duplicate and sort. #10
(07-10-2018, 02:57 AM)JohnTerry Wrote:
(07-09-2018, 01:26 PM)Mimiakira Wrote: Here is there error -

Traceback (most recent call last):
 File "test.py", line 2, in <module>
   from tqdm import tqdm
ImportError: No module named tqdm

you need to install tqdm module. "pip install tqdm"

Time Is my worst enemy at the moment, so If anyone can confirm this Is In fact the Issue, I'll be greatly appreciated.
[Image: AD83g1A.png]

Reply