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. 可以点下键到下一步
相关推荐
吃西瓜的年年20 小时前
1. 初识C语言
c语言·开发语言
ULTRA??20 小时前
初学protobuf,C++应用例子(AI辅助)
c++·python
CHANG_THE_WORLD20 小时前
Python 字符串全面解析
开发语言·python
不会c嘎嘎20 小时前
深入理解 C++ 异常机制:从原理到工程实践
开发语言·c++
永远都不秃头的程序员(互关)21 小时前
C语言 基本语法
c语言·开发语言
甄心爱学习21 小时前
CSP认证 备考(python)
数据结构·python·算法·动态规划
永远都不秃头的程序员(互关)21 小时前
Java核心技术精要:高效实践指南
java·开发语言·性能优化
databook21 小时前
数据会说谎?三大推断方法帮你“审问”数据真相
后端·python·数据分析
是Dream呀21 小时前
Python圣诞特辑:打造一棵会唱歌、会下雪的魔法圣诞树
开发语言·python·pygame
未来之窗软件服务21 小时前
幽冥大陆(四十一)美萍V10酒店门锁SDK C#语言仙盟插件——东方仙盟筑基期
开发语言·c#·仙盟创梦ide·东方仙盟·东方仙盟sdk·酒店智能门锁·东方仙盟 vos 智能浏览器