Sinisterly
Password count duplicate and sort. - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Password count duplicate and sort. (/Thread-Password-count-duplicate-and-sort)

Pages: 1 2


Password count duplicate and sort. - JohnTerry - 07-09-2018

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!!!')



RE: Password count duplicate and sort. - Vultra - 07-09-2018

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.


RE: Password count duplicate and sort. - JohnTerry - 07-09-2018

(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.


RE: Password count duplicate and sort. - mothered - 07-09-2018

(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?


RE: Password count duplicate and sort. - Vultra - 07-09-2018

(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.


RE: Password count duplicate and sort. - mothered - 07-09-2018

(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.


RE: Password count duplicate and sort. - Vultra - 07-09-2018

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


RE: Password count duplicate and sort. - Vi-Sion - 07-09-2018

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.


RE: Password count duplicate and sort. - JohnTerry - 07-10-2018

(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"


RE: Password count duplicate and sort. - mothered - 07-10-2018

(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.