Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- }
- }
- #! /usr/bin/env python3.6
- # -*- coding: utf-8 -*-
- def reader(fname):
- d={}
- fromto={}
- df=[]
- file = open(fname,"r")
- for line in file:
- # print (line)
- ll=line.strip().split('for')
- sfrom=''.join(ll[0].split())
- sto=ll[1].split()
- if sfrom in fromto: # почему-то проверка не рботает
- df = fromto[sfrom]
- for i in range(len(sto)):
- df.append(sto[i])
- fromto[sfrom]= df
- df.clear()
- print(fromto)
- if __name__ == '__main__':
- reader('list-100.list')
- from collections import Counter
- log = """
- """
- pairs = Counter()
- for line in log.splitlines():
- tmp = line.split()
- from_user = tmp[0]
- pairs.update((from_user, to_user) for to_user in tmp[2:])
- print(pairs)
- text = """
- """
- from collections import defaultdict
- from_by_to_list = defaultdict(list)
- for line in text.splitlines():
- line = line.strip()
- from_str, to_str = line.split('for')
- from_str = from_str.strip().split()[1]
- to_list = to_str.strip().split()
- from_by_to_list[from_str] += to_list
- print(from_by_to_list)
- print()
- for k, items in from_by_to_list.items():
- print('{} ({}):'.format(k, len(items)))
- for i, x in enumerate(items, 1):
- print(' {}. {}'.format(i, x))
- print()
- defaultdict(<class 'list'>, {'[email protected]': ['[email protected]', '[email protected]', '[email protected]', '[email protected]'], '[email protected]': ['[email protected]', '[email protected]']})
- [email protected] (4):
- [email protected] (2):
Add Comment
Please, Sign In to add comment