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. 可以点下键到下一步
相关推荐
Zzzz_my2 分钟前
正则表达式(RE)
pytorch·python·正则表达式
娇娇yyyyyy16 分钟前
QT编程(17): Qt 实现自定义列表模型
开发语言·qt
唐青枫25 分钟前
C#.NET SpinLock 深入解析:自旋锁原理、使用边界与性能取舍
c#·.net
天天鸭30 分钟前
前端仔写了个 AI Agent,才发现大模型只干了 10% 的活
前端·python·ai编程
ms_27_data_develop31 分钟前
Java枚举类、异常、常用类
java·开发语言
add45a1 小时前
C++编译期数据结构
开发语言·c++·算法
setmoon2141 小时前
使用Scikit-learn构建你的第一个机器学习模型
jvm·数据库·python
岁岁种桃花儿1 小时前
AI超级智能开发系列从入门到上天第四篇:AI应用方案设计
java·服务器·开发语言
Amnesia0_01 小时前
C++中的IO流
开发语言·c++
2401_891482171 小时前
C++模块化编程指南
开发语言·c++·算法