#字典排序
dic = {
"小強(qiáng)":89,
"阿黃":76,
"如花":96,
"華安":99,
"秋香":81
}
# data = [(v,k) for k,v in dic.items()]
# # print(data)
# result = sorted(data)
# print(result)
#第二種實(shí)現(xiàn)方式
# print(sorted(dic.items(), key=lambda x: x[1]))
# def add(x,y):
# return x+y
# print(add(5, 3))
#
#
# add2 = lambda x,y:x+y
#
# print(add2(4, 6))
#2 統(tǒng)計(jì)數(shù)據(jù)出現(xiàn)次數(shù),并列出前三個(gè)數(shù)
l = [4, 0, 2, 0, 4, 1, 7, 0, 2, 6, 8, 1, 5, 5, 10, 5, 6, 10, 5, 9]
#第一種
d = dict.fromkeys(l,0)
for i in l:
d[i]+=1
print(d)
#第二種
my_dic = {}
for i in l:
if i in my_dic:
my_dic[i]+=1
else:
my_dic[i] = 1
# print("my_dict:",my_dic)
#3 在pysie6種應(yīng)用
from PySide6.QtWidgets import *
from PySide6.QtCore import *
from PySide6.QtGui import QAction
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.menu = self.menuBar()
self.file_menu = self.menu.addMenu('File')
self.actions = {
"Open": self.open_file,
"Save": self.save_file,
"Exit": self.exit_app
}
for action_name, action_function in self.actions.items():
action = QAction(action_name, self)
action.triggered.connect(action_function)
self.file_menu.addAction(action)
def open_file(self):
print("打開文件操作")
def save_file(self):
print("保存文件操作")
def exit_app(self):
self.close()
app = QApplication([])
window = MainWindow()
window.show()
app.exec()
承擔(dān)因您的行為而導(dǎo)致的法律責(zé)任,
本站有權(quán)保留或刪除有爭(zhēng)議評(píng)論。
參與本評(píng)論即表明您已經(jīng)閱讀并接受
上述條款。