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 分钟前
Rust HashSet 与 BTreeSet深度剖析
开发语言·后端·rust
长存祈月心5 分钟前
Rust BTreeMap 红黑树
开发语言·后端·rust
好奇的候选人面向对象25 分钟前
基于 Element Plus 的 TableColumnGroup 组件使用说明
开发语言·前端·javascript
技术支持者python,php35 分钟前
ModbusRtc与ModbusTCP,esp32
c#
wjs202436 分钟前
CSS3 圆角
开发语言
颜颜yan_38 分钟前
Rust impl块的组织方式:从基础到实践的深度探索
开发语言·后端·rust
代码改善世界39 分钟前
Rust 入门基础:安全、并发与高性能的系统编程语言
开发语言·安全·rust
咕白m6251 小时前
如何用 C# 将 Excel 文件转换为 HTML 格式?
c#·.net
没有故事、有酒1 小时前
Axios
开发语言·php
xiaozaq1 小时前
java 正则表达式 所有的优先级
java·开发语言·正则表达式