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. 可以点下键到下一步
相关推荐
一个响当当的名号2 分钟前
lectrue9 索引并发控制
java·开发语言·数据库
2401_832131953 分钟前
模板错误消息优化
开发语言·c++·算法
进阶小白猿6 分钟前
Java技术八股学习Day30
java·开发语言·学习
lead520lyq8 分钟前
Golang本地内存缓存
开发语言·缓存·golang
zhaotiannuo_19989 分钟前
Python之2.7.9-3.9.1-3.14.2共存
开发语言·python
Keep_Trying_Go14 分钟前
基于GAN的文生图算法详解ControlGAN(Controllable Text-to-Image Generation)
人工智能·python·深度学习·神经网络·机器学习·生成对抗网络·文生图
2601_9498683619 分钟前
Flutter for OpenHarmony 电子合同签署App实战 - 主入口实现
开发语言·javascript·flutter
LostSpeed36 分钟前
openpnp - python2.7 script - 中文显示乱码,只能显示英文
python·openpnp
helloworldandy40 分钟前
高性能图像处理库
开发语言·c++·算法
2401_8365631842 分钟前
C++中的枚举类高级用法
开发语言·c++·算法