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. 可以点下键到下一步
相关推荐
汤姆yu9 小时前
基于python大数据的高校舆情监测系统的设计与实现
大数据·开发语言·python·分享·分析·舆情
Cory.眼9 小时前
Python爬虫实战:从入门到进阶
开发语言·爬虫·python
qq_589666059 小时前
Java继承
java·开发语言
八角.。9 小时前
面向对象-多态
java·开发语言
qq_422152579 小时前
Token到底是什么?Tokenizer分词机制与中文token开销入门科普
人工智能·python·深度学习
@卓越俊逸_角立杰出@9 小时前
快速学会 Java 实现意图识别:从规则匹配到 BiLSTM 分类器
java·开发语言·人工智能
吴可可12310 小时前
C#重写机制与CAD图元开发要点
c#
小小龙学IT10 小时前
simdjson:利用 SIMD 指令实现 GB/s 级 JSON 解析的 C++ 开源库
开发语言·c++·json
buyue__10 小时前
Python实现连接MySQL数据库并执行目录下的所有SQL文件,遇到错误时终止执行。
python·mysql
A_nanda10 小时前
c#WPF开发常见问题
开发语言·c#·wpf