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





Messages In This Thread
Password count duplicate and sort. - by JohnTerry - 07-09-2018, 09:31 AM