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. 可以点下键到下一步
相关推荐
ん贤14 分钟前
Go channel 深入解析
开发语言·后端·golang
小陳参上2 小时前
用Python创建一个Discord聊天机器人
jvm·数据库·python
2301_789015622 小时前
DS进阶:AVL树
开发语言·数据结构·c++·算法
Filotimo_4 小时前
5.3 Internet基础知识
开发语言·php
识君啊4 小时前
Java异常处理:中小厂面试通关指南
java·开发语言·面试·异常处理·exception·中小厂
minstbe4 小时前
IC设计私有化AI助手实战:基于Docker+OpenCode+Ollama的数字前端综合增强方案(进阶版)
人工智能·python·语言模型·llama
zyq99101_15 小时前
优化二分查找:前缀和降复杂度
数据结构·python·蓝桥杯
qyzm5 小时前
天梯赛练习(3月13日)
开发语言·数据结构·python·算法·贪心算法
leluckys6 小时前
swift- Swift中常见的面试题
开发语言·汇编·swift
BUG_MeDe6 小时前
json格式字符串解析的简单使用 libjson-c
c语言·开发语言·json