2024/5/20
所花时间:1小时
代码行:70行
博客量:1篇
了解到的知识点:
with open('nb.txt', 'r') as file:
lines = file.readlines()
word_count = 0
valid_lines = 0
for line in lines:
line = line.strip()
# 统计有效行数
if len(line) > 0:
valid_lines += 1
# 统计单词数
words = line.split()
word_count += len(words)
print("单词数:", word_count)
print("有效行数:", valid_lines)
import jieba
# 定义中文级联菜单
menu = {
'首页': {
'关于我们': {
'团队介绍': None,
'联系方式': None
},
'产品中心': {
'产品1': None,
'产品2': None
}
}
}
# 打印中文级联菜单
def print_menu(menu, level=0):
for key in menu:
seg_list = jieba.lcut(key)
print(' ' * level + ''.join(seg_list))
if menu[key] is not None:
print_menu(menu[key], level + 1)
print_menu(menu)