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. 可以点下键到下一步
相关推荐
chao1898442 分钟前
基于C# WinForm实现的仿微信打飞机游戏
游戏·微信·c#
cheems952716 分钟前
锁策略的介绍
java·开发语言
清水白石00818 分钟前
《Python × 数据库:用 SQLAlchemy 解锁高效 ORM 编程的艺术》
开发语言·python·json
星依网络25 分钟前
使用LabelImg工具标注数据(游戏辅助脚本开发)
python·游戏引擎·图形渲染·骨骼绑定
站大爷IP25 分钟前
Appium实现Android应用数据爬取:从环境搭建到实战优化
python
风中月隐25 分钟前
C语言中以坐标的方式图解“字母金字塔”的绘制
c语言·开发语言·算法·字母金子塔·坐标图解法
Arva .30 分钟前
说说线程的生命周期和状态
java·开发语言
1001101_QIA33 分钟前
C++中不能复制只能移动的类型
开发语言·c++
tryxr37 分钟前
HashTable、HashMap、ConcurrentHashMap 之间的区别
java·开发语言·hash
serendipity_hky39 分钟前
【go语言 | 第5篇】channel——多个goroutine之间通信
开发语言·后端·golang