deque, ordered_dict, defaultdict, counter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | from collections import deque deque_list = deque() for i in range(5): deque_list.append(i) deque_list.appendleft(10) from collections import OrderedDict d = OrderedDict() d['x'] = 100 d['y'] = 200 d['z'] = 300 d['l'] = 500 for k, v in d.items(): print(k, v) from collections import defaultdict d = defaultdict(object) d = defaultdict(lambda:0) print(d["first"]) text = "best in the world".split() print(text) word_count = defaultdict(object) word_count = defaultdict(lambda:0) for word in text: word_count[word] +=1 for i, v in OrderedDict(sorted(word_count.items(), key=lambda t:t[1], reverse=True)).items(): print(i, v) from collections import Counter c = Counter() c = Counter('gallahad') print(c) | cs |
ref : python for machine learning
'* Computer Science > py' 카테고리의 다른 글
bulk printer with py (0) | 2018.12.07 |
---|---|
git bash에서 파이썬으로 git untracked files 제거 (0) | 2018.08.15 |
Asterisk (0) | 2018.07.09 |
zip, enumurate, lambda, map reduce (0) | 2018.07.09 |
join & traslate & title (0) | 2018.03.04 |