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. 可以点下键到下一步
相关推荐
cch89184 小时前
汇编与Java:底层与高层的编程对决
java·开发语言·汇编
荒川之神5 小时前
拉链表概念与基本设计
java·开发语言·数据库
chushiyunen5 小时前
python中的@Property和@Setter
java·开发语言·python
禾小西6 小时前
Java中使用正则表达式核心解析
java·python·正则表达式
yoyo_zzm6 小时前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python
小樱花的樱花6 小时前
C++ new和delete用法详解
linux·开发语言·c++
froginwe116 小时前
C 运算符
开发语言
fengfuyao9856 小时前
低数据极限下模型预测控制的非线性动力学的稀疏识别 MATLAB实现
开发语言·matlab
摇滚侠6 小时前
搭建前端开发环境 安装 nodejs 设置淘宝镜像 最简化最标准版本 不使用 NVM NVM 高版本无法安装低版本 nodejs
java·开发语言·node.js