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. 可以点下键到下一步
相关推荐
岁岁的O泡奶8 分钟前
ctfshow_crypto_萌新赛
经验分享·python·密码学·crypto
YuanDaima204810 分钟前
队列与单调队列基础原理与题目说明
人工智能·python·算法·leetcode·队列·手撕代码
亚空间仓鼠16 分钟前
Python学习日志(四):实例
开发语言·python·学习
Fanfanaas18 分钟前
Linux 系统编程 进程篇 (二)
linux·运维·服务器·c语言·开发语言·学习
2301_7641505621 分钟前
Redis如何控制只读从库的安全_配置replica-read-only防止从节点数据被意外篡改
jvm·数据库·python
油丶酸萝卜别吃21 分钟前
高效处理数组差异:JS中新增、删除、交集的最优解(Set实现)
开发语言·前端·javascript
HoneyMoose23 分钟前
Npmp 安装时候提示警告: error (ERR_INVALID_THIS)
开发语言
DaqunChen24 分钟前
SQL如何检测分组内是否存在满足条件的数据_EXISTS结合分组
jvm·数据库·python
gskyi24 分钟前
时间格式化神器:智能显示相对时间
开发语言·javascript·ecmascript
段一凡-华北理工大学25 分钟前
【大模型+知识图谱+工业智能体技术架构】~系列文章02:工业知识图谱的构建与知识表示学习方法!!!
数据结构·python·神经网络·知识图谱·物理系统·神经逆向渲染