from collections import namedtuple
User = namedtuple('User', ['first_name', 'last_name', 'age'])
user1 = User('Максим', 'Бекурин', 35)
print(user1)
#Вывод: User(first_name='Максим', last_name='Бекурин', age=35)
print(user1.first_name)
#Вывод: Максим
from collections import deque
seq = [1, 2, 3, 4, 5]
deq = deque(seq)
deq.append(6) # добавление в конец
deq.appendleft(0) # добавление в начало
print(deq)
#Вывод: deque([0, 1, 2, 3, 4, 5, 6])
deq.extend([7, 8, 9]) # добавление в конец
deq.extendleft([-1, -2, -3]) # добавление в начало
print(deq)
#Вывод: deque([-3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
from collections import ChainMap
letters = {'a': 1, 'b': 2}
vowels = {'a': 2, 'b': 0, 'c': 0, 'd': 0, 'e': 1}
chain = ChainMap(letters, vowels)
print(chain['b'])
# Вывод: 2
from collections import OrderedDict
d = OrderedDict.fromkeys([])
d['Максим'] = 10
d['Владимир'] = 20
d['Иван'] = 30
print(d)
# Вывод: OrderedDict([('Максим', 10), ('Владимир', 20), ('Иван', 30)])
d.move_to_end('Максим')
print(d)
# Вывод: OrderedDict([('Владимир', 20), ('Иван', 30), ('Максим', 10)])
d.popitem(last=True)
print(d)
# Вывод: OrderedDict([('Владимир', 20), ('Иван', 30)])
from collections import Counter
age = [32, 33, 34, 33, 45, 34, 45, 23, 32, 23, 45, 23, 21, 25, 45]
age_counter = Counter(age)
print(age_counter)
# Вывод: Counter({45: 4, 23: 3, 32: 2, 33: 2, 34: 2, 21: 1, 25: 1})
from collections import Counter
age_counter = Counter({45: 4, 23: 3, 32: 2, 33: 2, 34: 2, 21: 1, 25: 1})
age = list(age_counter.elements())
print(age)
# Вывод: [45, 45, 45, 45, 23, 23, 23, 32, 32, 33, 33, 34, 34, 21, 25]
from collections import Counter
age = [32, 33, 34, 33, 45, 34, 45, 23, 32, 23, 45, 23, 21, 25, 45]
age_counter = Counter(age)
age_n2 = age_counter.most_common(2)
print(age_n3)
# Вывод: [(45, 4), (23, 3)]
from collections import Counter
age = [32, 33, 34, 33, 45, 34, 45, 23, 32, 23, 45, 23, 21, 25, 45]
age_counter = Counter(age)
age_unique = age_counter.most_common()[-1:]
print(age_unique)
# Вывод: [(25, 1)]
from collections import defaultdict
s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
d = defaultdict(list)
for k, v in s:
d[k].append(v)
print(dict(d))
# Вывод: {'yellow': [1, 3], 'blue': [2, 4], 'red': [1]}