python: heap Tree, hash Table

 

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# encoding: utf-8
# 版權所有 2024 ©塗聚文有限公司
# 許可資訊查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述: 主、子表單 窗體傳值  Parent-child form operations
# Author    : geovindu,Geovin Du 塗聚文.
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/10/24 20:09
# User      : geovindu
# Product   : PyCharm
# Project   : IctGame
# File      : ui/main.py
# explain   : 學習
 
import heapq  # https://docs.python.org/3/library/heapq.html
import hashlib
 
h = [10, 21, 5, 12, 88, 3, 100, 111, 200]
heapq.heapify(h)  # 取出了最小的
print(h)
val = heapq.heappop(h)
print(h)
print('最小三个:', heapq.nlargest(3, h))
print('最大三个:', heapq.nsmallest(3, h))
print(h)
 
 
def checkname(name: str):
    if voted[name]:
        print('你已投过票了')
    else:
        print('欢迎你投票')
        voted[name] = True
 
 
voted = {'Jason': None, 'Lisa': None, 'Mike': None}
 
while True:
    name = input("请输入姓名:")
    if name in voted:
        checkname(name)
    else:
        print('你不是投票者')
    yn = input("y/n?")
    if yn == 'y' or yn == 'Y':
        pass
    else:
        break
 
data = hashlib.md5()  #sha1()
data.update(b'geovindu')
print('hash value=',data.digest())
print('hassh value(16 byte)',data.hexdigest())
print(type(data))
print(type(data.hexdigest()))
school='涂聚文大学'
data.update(school.encode('utf-8'))
print('hash value=',data.digest())
print('hassh value(16 byte)',data.hexdigest())
print(type(data))
print(type(data.hexdigest()))
print(hashlib.algorithms_available) #平台的杂凑算法  {'sha512', 'shake_128', 'whirlpool', 'sha3_256', 'sha256', 'sha1', 'sha512_224', 'mdc2', 'md5-sha1', 'sha3_224', 'sha3_384', 'shake_256', 'blake2s', 'md5', 'sha224', 'sm3', 'blake2b', 'md4', 'sha384', 'sha3_512', 'sha512_256', 'ripemd160'}
 
filename='1.txt'
with open(filename,mode='rb') as fn:
    btxt=fn.read()
    data.update(btxt)
print('hash value=',data.digest())
print('hassh value(16 byte)',data.hexdigest())
print(type(data))
print(type(data.hexdigest()))

  

posted @   ®Geovin Du Dream Park™  阅读(7)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2022-10-25 Python: Visitor Pattern
2022-10-25 Python: Strategy Pattern
< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示