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. 可以点下键到下一步
相关推荐
磊 子6 分钟前
多态类原理+四种类型转换+异常处理
开发语言·c++·算法
脆皮炸鸡7558 分钟前
库制作与原理~动态链接
linux·开发语言·经验分享·笔记·学习方法
XMYX-010 分钟前
26 - Go recover 捕获错误:优雅恢复的真正意义
开发语言·golang
小白学大数据10 分钟前
基于大模型的Python智能爬虫:语义识别与数据清洗实践
开发语言·爬虫·python·数据分析
Cloud_Shy61813 分钟前
Python 数据分析基础入门:《Excel Python:飞速搞定数据分析与处理》学习笔记系列(附录 B 高级 VS Code 功能)
vscode·python·jupyter·数据分析·excel
进击切图仔17 分钟前
从零手写 RAG
python·huggingface·rag
Dxy123931021624 分钟前
Python请求方式介绍:JSON、表单及其他常见数据传输格式
数据库·python·json
迷渡29 分钟前
聊一聊 Bun 用 Rust 重写这件事
开发语言·后端·rust
西洼工作室31 分钟前
个人开发者接入阿里云号码认证服务AliCloud-NirvanaPns实现一键登录
python·阿里云·uni-app·全栈·认证授权
古怪今人38 分钟前
Gradle构建工具 Groovy/Kotlin DSL的现代化自动化构建工具
开发语言·kotlin·自动化