Python 基础知识

Python实现wordcount

复制代码
import re
from collections import defaultdict

def wordcount(text):
    words = re.findall(r'\b\w+\b', text.lower())
    
    word_count = defaultdict(int)
    for word in words:
        word_count[word] += 1
    
    return dict(word_count)

text = """Got this panda plush toy for my daughter's birthday,
who loves it and takes it everywhere. It's soft and
super cute, and its face has a friendly look. It's
a bit small for what I paid though. I think there
might be other options that are bigger for the
same price. It arrived a day earlier than expected,
so I got to play with it myself before I gave it
to her."""

result = wordcount(text)
print(result)

debug

debug笔记

复制代码
1. 需要下载按照扩展插件
2. 需要创建配置文件
3. 需要在代码左边点个点
4. 可以点下键到下一步
相关推荐
勿忘,瞬间2 分钟前
多线程之进阶修炼
java·开发语言
萌萌站起4 分钟前
Vscode 中 python模块的导入问题
ide·vscode·python
是小蟹呀^18 分钟前
【总结】提示词工程
python·llm·prompt·agent
YBAdvanceFu20 分钟前
从零构建智能体:深入理解 ReAct Plan Solve Reflection 三大经典范式
人工智能·python·机器学习·数据挖掘·多智能体·智能体
hoiii18731 分钟前
CSTR反应器模型的Simulink-PID仿真(MATLAB实现)
开发语言·matlab
王夏奇37 分钟前
python中的__all__ 具体用法
java·前端·python
王夏奇41 分钟前
pycharm中3种不同类型的python文件
ide·python·pycharm
炘爚1 小时前
C++ 右值引用与程序优化
开发语言·c++
小陈的进阶之路1 小时前
Selenium 滑动 vs Appium 滑动
python·selenium·测试工具·appium
Mike_6661 小时前
txt_json和xml_json
xml·python·json