随笔分类 - 字典
有关字典的PYTHON程序
摘要:import jieba with open("qi.txt","r",encoding = "utf-8") as f: hua = f.read()word = jieba.cut(hua) count = {}for ci in word: if ci in count: count[ci]
阅读全文
摘要:#假设你是一名老师,你想要管理你班级学生的成绩。你可以使用Python的字典来记录每个学生的成绩。以下是一个简单的程序: # 创建一个空字典来存储学生成绩student_scores = {} # 添加学生成绩记录student_scores['张三'] = {'语文': 90, '数学': 80,
阅读全文
摘要:perators = {"+": lambda x, y: x + y, "-": lambda x, y: x - y, "*": lambda x, y: x * y, "/": lambda x, y: x / y} op = input("请输入运算符(+、-、*、/):")num1 = f
阅读全文
摘要:#假设你是一家水果店的老板,你想要统计每种水果的销售情况。你可以使用Python的字典来记录每种水果的销售数量和总销售额。以下是一个简单的程序: # 创建一个空字典来存储水果销售情况fruit_sales = {} # 添加销售记录fruit_sales['苹果'] = {'数量': 100, '总
阅读全文
摘要:text = input("请输入一段文本:")words = text.split()print(words)word_count = {} for word in words: if word in word_count: word_count[word] += 1 else: word_cou
阅读全文
摘要:""""这个程序可以读取一个文本文件,统计每个单词出现的次数,并按照出现次数从高到低排序。程序可以用字典来记录每个单词出现的次数。"""with open("text.txt", "r") as f: text = f.read() # 将文本分割成单词words = text.split() #
阅读全文
摘要:import random chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-="length = int(input("请输入密码长度:")) password = ""for i
阅读全文
摘要:# 初始化英汉词典dictionary = { "apple": "苹果", "banana": "香蕉", "cherry": "樱桃", "orange": "橙子", "pear": "梨子"} # 获取用户输入word = input("请输入一个英文单词:") # 查找对应的中文翻译if
阅读全文