-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcounter_adv.py
More file actions
26 lines (18 loc) · 909 Bytes
/
counter_adv.py
File metadata and controls
26 lines (18 loc) · 909 Bytes
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
from collections import Counter, deque
#################################################### Counter ####################################################
words = ['a', 'b', 'c', 'f', 'c', 'f','c', 'f', 'a']
words_count = Counter(words)
# print(words_count)
# print(words_count.most_common(2))
# print(sorted(words_count.elements()))
#################################################### deque ####################################################
# deque is a double-ended queue. It can be used to add or remove elements from both ends.
# It is thread-safe, which means that multiple threads can access it simultaneously.
# It is faster than the list in terms of execution time for appending and popping elements.
custom_deque = deque([], maxlen=3)
for i in range(1,10):
custom_deque.append(i)
print(custom_deque)
# custom_deque.rotate()
custom_deque.rotate(3) # rotate right
print(custom_deque)