sairate 7df250638d chore: 添加项目基础结构和示例代码
- 创建 .idea 目录和相关配置文件,设置项目结构
- 添加多个课堂成果示例代码,涵盖不同主题和功能
- 创建和配置 .gitignore 文件,忽略特定文件和目录
2025-07-05 09:36:00 +08:00

12 lines
533 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 单词出现频次统计
string = "to be or not to be that is a question" # 定义变量存储字符串
lis = string.split(" ") # 使用分割函数将字符串转为列表
count = {} # 定义一个空字典
for x in lis: # 遍历列表
if x not in count: # 判断列表元素是否在字典中
count[x] = 1 # 如果元素还不在字典中,那么就添加键值对
else:
count[x] += 1 # 如果元素已经在字典中那么就将键对应的值加1
print(count) # 打印字典