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. 可以点下键到下一步
相关推荐
LT>_<1 分钟前
flink遇到的问题
大数据·python·flink
tryxr5 分钟前
Java 中 this 关键字的使用场景
java·开发语言·类与对象·this关键字
写代码的【黑咖啡】6 分钟前
面向对象编程入门:从类与对象到构造函数
开发语言·python
沐知全栈开发7 分钟前
Perl POD 文档
开发语言
luo_yu_11069 分钟前
安装chroma的时候报错
python·chroma
Dargon2889 分钟前
Simulink的回调函数(二)
开发语言·matlab·simulink·mbd软件开发
Daily Mirror12 分钟前
Day 43 训练和测试的规范写法
python
ICT技术最前线12 分钟前
路由策略优化基本思路和方法
开发语言·php
lly20240613 分钟前
Docker 安装 Ubuntu
开发语言
natide13 分钟前
词汇/表达差异-7-Alias覆盖率
人工智能·pytorch·python·深度学习·自然语言处理