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. 可以点下键到下一步
相关推荐
CaracalTiger26 分钟前
什么是Clawdbot?Clawdbot下载、安装、配置教程(最新版Moltbot)
python·编辑器·aigc·idea·ai编程·intellij idea·agi
星火开发设计30 分钟前
枚举类 enum class:强类型枚举的优势
linux·开发语言·c++·学习·算法·知识
WJX_KOI5 小时前
Open Notebook 一个开源的结合AI的记笔记软件
python
喜欢吃燃面6 小时前
Linux:环境变量
linux·开发语言·学习
0思必得06 小时前
[Web自动化] 反爬虫
前端·爬虫·python·selenium·自动化
徐徐同学6 小时前
cpolar为IT-Tools 解锁公网访问,远程开发再也不卡壳
java·开发语言·分布式
LawrenceLan6 小时前
Flutter 零基础入门(二十六):StatefulWidget 与状态更新 setState
开发语言·前端·flutter·dart
2301_822382766 小时前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python
m0_748229996 小时前
Laravel8.X核心功能全解析
开发语言·数据库·php
喵手6 小时前
Python爬虫实战:从零搭建字体库爬虫 - requests+lxml 实战采集字体网字体信息数据(附 CSV 导出)!
爬虫·python·爬虫实战·零基础python爬虫教学·csv导出·采集字体库数据·字体库字体信息采集