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. 可以点下键到下一步
相关推荐
兮动人1 小时前
C语言之指针入门
c语言·开发语言·c语言之指针入门
ada7_1 小时前
LeetCode(python)78.子集
开发语言·数据结构·python·算法·leetcode·职场和发展
我送炭你添花2 小时前
Pelco KBD300A 模拟器:06+5.串口实现的逻辑优化、配置管理与协议完善(二次迭代)
python·运维开发
databook2 小时前
前注意加工:让你的图表抓住读者的眼球
python·数据分析·数据可视化
知行学思2 小时前
Python配置管理完全指南:从dotenv到pydantic_settings
数据库·python·fastapi·环境变量·配置管理·pydantic·dotenv
nbsaas-boot2 小时前
Go 项目中如何正确升级第三方依赖(Go Modules 实战指南)
开发语言·后端·golang
wadesir3 小时前
C++基本数据类型详解(零基础掌握C++核心数据类型)
java·开发语言·c++
skywalk81633 小时前
wow文件处理trinitycore的文件处理
开发语言·游戏
一路往蓝-Anbo4 小时前
STM32单线串口通讯实战(五):RTOS架构 —— 线程安全与零拷贝设计
c语言·开发语言·stm32·单片机·嵌入式硬件·观察者模式·链表
leiming64 小时前
c++ map容器
开发语言·c++·算法