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. 可以点下键到下一步
相关推荐
多多*8 分钟前
上传文件相关业务,采用策略模式+模版方法模式进行动态解耦
java·开发语言
ZhengEnCi26 分钟前
CMD 与 Python 完全区别指南-小白必看的编程入门解惑宝典
windows·python
Hs_QY_FX36 分钟前
逻辑回归实战:泰坦尼克号生存预测
python·逻辑回归
赴前尘38 分钟前
Go 通道非阻塞发送:优雅地处理“通道已满”的场景
开发语言·后端·golang
weixin_456904271 小时前
以太网与工业以太网通信C#开发
开发语言·c#
野猪亨利6671 小时前
Qt day1
开发语言·数据库·qt
lastHertz1 小时前
Golang 项目中使用 Swagger
开发语言·后端·golang
惜月_treasure1 小时前
LlamaIndex多模态RAG开发实现详解
开发语言·python·机器学习
isaki1372 小时前
qt day1
开发语言·数据库·qt
流星白龙2 小时前
【Qt】4.项目文件解析
开发语言·数据库·qt