[python] Advanced programming skills (1) Screening and statistics

Do not stamp, original link:
https://www.bilibili.com/video/BV1b5411s76z?p=4

Data storage filters data.
Insert picture description here
Tuple elements are named and can be called in the way of class objects.
Insert picture description here
Insert picture description here
Statistic frequency of occurrence.
Insert picture description here
Insert picture description here
Dictionary sorted by value
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

from random import randint
from collections import Counter
from functools import reduce

data1 = [randint(10,100) for _ in range(50)]
count1 = Counter(data1)

data2 = [randint(10,100) for _ in range(50)]
count2 = Counter(data2)

data3 = [randint(10,100) for _ in range(50)]
count3 = Counter(data3)


print(reduce(lambda a, b: a & b , map(dict.keys,[count1,count2,count3])))

Guess you like

Origin blog.csdn.net/Sgmple/article/details/112768267