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 分钟前
TypeWell全攻略(四):AI键位分析,让数据开口说话
前端·人工智能·后端·python·ai·交互
froginwe114 分钟前
JavaScript 类型转换
开发语言
Drifter_yh7 分钟前
「JVM」 并发编程基石:Java 内存模型(JMM)与 Synchronized 锁升级原理
java·开发语言·jvm
码界筑梦坊11 分钟前
220-基于Python的诺贝尔奖数据可视化分析系统
开发语言·python·信息可视化·数据分析·毕业设计·fastapi
m0_5312371716 分钟前
C语言-编程实例
c语言·开发语言·数据结构
风轻扬77717 分钟前
SqlAlchemy异步IO
python·异步io
bai_lan_ya20 分钟前
嵌入式linux学习--makefile的使用以及通用解析
开发语言·前端·javascript
waves浪游21 分钟前
库制作与原理(上)
linux·运维·服务器·开发语言·c++
276695829224 分钟前
微博评论采集
开发语言·python·微博·微博评论·微博评论采集