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 小时前
告别掉帧与素材损毁:威联通 QuTS hero 如何重塑影视后期协同工作流
前端·网络·人工智能·python
Dxy12393102161 小时前
Python 根据列表中某字段排序:从基础到进阶
开发语言·windows·python
competes1 小时前
学生需求 交易累计积分,积分兑换奖品
java·大数据·开发语言·人工智能·java-ee
splage1 小时前
Java进阶——IO 流
java·开发语言·python
青桔柠薯片1 小时前
从C语言到裸机运行:i.MX6ULL 的 GPIO 控制与编译链接过程分析
c语言·开发语言·imx6ull
cliffordl1 小时前
设计模式(python)
python·设计模式
OasisPioneer1 小时前
现代 C++ 全栈教程 - Modern-CPP-Full-Stack-Tutorial
开发语言·c++·开源·github
weixin_537590452 小时前
《C程序设计语言》练习答案(练习1-13)
c语言·开发语言·c#
always_TT2 小时前
从Python_Java转学C语言需要注意什么?
java·c语言·python
2301_793804692 小时前
定时任务专家:Python Schedule库使用指南
jvm·数据库·python