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 分钟前
【HTML】核心标签与【Python爬虫库】实战指南
css·爬虫·python·html
绿浪19841 分钟前
C#与C++高效互操作指南
c++·c#
shilei_c6 分钟前
qt qDebug无输出问题解决
开发语言·c++·算法
pop_xiaoli8 分钟前
effective-Objective-C 第一章阅读笔记
开发语言·笔记·ios·objective-c·cocoa·xcode
jghhh018 分钟前
基于C#的CAN总线BMS上位机开发方案
开发语言·c#
serve the people8 分钟前
python环境搭建 (七) pytest、pytest-asyncio、pytest-cov 试生态的核心组合
开发语言·python·pytest
java1234_小锋11 分钟前
分享一套不错的基于Python的Django宠物信息管理系统
开发语言·python·宠物
2401_8414956412 分钟前
【Web开发】基于Flask搭建简单的应用网站
后端·python·flask·视图函数·应用实例·路由装饰器·调试模式
一切尽在,你来13 分钟前
C++ 零基础教程 - 第4讲-实现简单计算器
开发语言·c++
女王大人万岁20 分钟前
Go语言JSON标准库(encoding/json):功能解析与实战指南
服务器·开发语言·后端·golang·json