python: heap Tree, hash Table

 

# 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 @ 2024-10-25 04:36  ®Geovin Du Dream Park™  阅读(5)  评论(0编辑  收藏  举报