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. 可以点下键到下一步
相关推荐
超级大福宝5 小时前
用买火车票的例子讲解Java反射的作用
java·开发语言·后端
小则又沐风a5 小时前
第一章:C++入门基础--- c++入门门槛高? 逐步剖析c++语法 成为c++大师
开发语言·c++
XW01059995 小时前
6-1输入列表,求列表元素和(eval输入应用)
python
川石课堂软件测试5 小时前
接口测试需要注意的一些BUG
网络·数据库·python·单元测试·bug·压力测试·tornado
2401_853576505 小时前
定时任务专家:Python Schedule库使用指南
jvm·数据库·python
Oueii5 小时前
如何为开源Python项目做贡献?
jvm·数据库·python
小鸡吃米…5 小时前
Python 中的并发 —— 进程池
linux·服务器·开发语言·python
小王不爱笑1325 小时前
Java 异常全解析:从原理到实战,搞定异常处理
java·开发语言
Techblog of HaoWANG5 小时前
目标检测与跟踪(10)-- Jetson Xavier NX刷机、移植&部署YOLOv8量化模型(中)
python·yolo·目标检测·onnx·量化部署
历程里程碑5 小时前
40 UDP - 2 C++实现英汉词典查询服务
linux·开发语言·数据结构·c++·ide·c#·vim