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 分钟前
go语言学习(基本数据类型)
开发语言·学习·golang·数据类型
Y001112365 分钟前
MySQL-进阶
开发语言·数据库·sql·mysql
Crazy________11 分钟前
docker4.8
java·开发语言·eureka
小白学大数据12 分钟前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
山甫aa14 分钟前
List 容器 -----C++的stl学习
开发语言·c++·学习
cch891815 分钟前
Laravel 2.x:早期框架的奠基之路
java·开发语言
t1987512818 分钟前
光伏发电MPPT(最大功率点跟踪)MATLAB仿真程序
开发语言·matlab
Hui Baby22 分钟前
springboot读取配置文件
后端·python·flask
阿Y加油吧28 分钟前
回溯法经典难题:N 皇后问题 深度解析 + 二分查找入门(搜索插入位置)
开发语言·python
leo_messi9433 分钟前
2026版商城项目(三)-- ES+认证服务
后端·python·django