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. 可以点下键到下一步
相关推荐
韩立学长12 小时前
【开题答辩实录分享】以《计算机类专业招聘信息爬取与查询系统设计与实现》为例进行答辩实录分享
python·scrapy·django
weixin_3077791312 小时前
Jenkins Branch API插件详解:多分支项目管理的核心引擎
java·运维·开发语言·架构·jenkins
@木辛梓12 小时前
结构体 结构体c++
开发语言·c++
kyle~12 小时前
虚拟仪器LabView(VI)
c++·python·ros·labview
小股虫12 小时前
消息中间件关键技术、设计原理与实现架构总纲
java·开发语言·架构
风萧萧199912 小时前
Java:PPT转图片
java·python·powerpoint
洲星河ZXH12 小时前
Java,日期时间API
java·开发语言·python
前端老曹12 小时前
Jspreadsheet CE V5 使用手册(保姆版) 二
开发语言·前端·vue.js·学习
秋邱13 小时前
AR 定位技术深度解析:从 GPS 到视觉 SLAM 的轻量化实现
开发语言·前端·网络·人工智能·python·html·ar
Boop_wu13 小时前
[Java EE] 多线程进阶(3) [线程安全集合类]
开发语言·windows·python