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. 可以点下键到下一步
相关推荐
bug总结几秒前
前端开发中为什么要使用 URL().origin 提取接口根地址
开发语言·前端·javascript·vue.js·html
少吃零食多运动2 分钟前
【Jupyter notebook修改工作目录】
python·jupyter
Swizard17 分钟前
别买树莓派了!3步教你在安卓手机上跑通 CPython + PaddleOCR,打造随身 AI 识别终端
python·ai·移动开发
晨曦夜月35 分钟前
笔试强训day7
开发语言·c++·算法
Kurbaneli37 分钟前
先啃C语言还是直奔目标?
开发语言
weixin_307779131 小时前
Jenkins Pipeline 完全指南:核心概念、使用详解与最佳实践
开发语言·ci/cd·自动化·jenkins·etl
kk”1 小时前
c++红黑树
开发语言·c++
Gomiko1 小时前
JavaScript DOM 原生部分(二):元素内容修改
开发语言·javascript·ecmascript
Z_W_H_1 小时前
【C#】C#中值类型和引用类型参数传递的区别
开发语言·c#
Data_agent1 小时前
实战:用Splash搞定JavaScript密集型网页渲染
开发语言·javascript·ecmascript