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. 可以点下键到下一步
相关推荐
筱砚.几秒前
【C++——文件操作案例】
开发语言·c++
kwg1262 分钟前
Dify二次开发构建api后端Docker离线镜像方案
服务器·人工智能·python
Zfox_6 分钟前
【Go】 协程和 channel
开发语言·后端·golang
a***13147 分钟前
【玩转全栈】----Django制作部门管理页面
后端·python·django
杨超越luckly16 分钟前
Python应用指南:利用高德地图采集AOI数据
python·arcgis·高德地图·数据可视化·aoi数据
向上_5035829121 分钟前
Android之kotlin学习
开发语言·学习·kotlin
木易 士心22 分钟前
Kotlin vs Swift:现代移动开发的“双子星”全面对比
开发语言·kotlin·swift
梁正雄23 分钟前
5、python 模块与包
linux·服务器·python
I_ltt_Itw,24 分钟前
Python协程学习笔记
开发语言·网络·python
大雨淅淅26 分钟前
【编程语言】Kotlin:从新手到大神的进阶之路
android·开发语言·kotlin