任务: https://github.com/InternLM/Tutorial/blob/camp3/docs/L0/Python/task.md
完成:
任务1:Python实现wordcount
import re
from collections import defaultdictdef wordcount(text):# 转换为小写并使用正则表达式分割单词words = re.findall(r'\b\w+\b', text.lower())# 使用 defaultdict 来自动处理字典中不存在的键word_counts = defaultdict(int)# 统计每个单词出现的次数for word in words:word_counts[word] += 1return dict(word_counts)if __name__ == "__main__":# 示例text = "One, world! one dream."result = wordcount(text)print(result)
任务2:Vscode连接InternStudio debug笔记