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. 可以点下键到下一步
相关推荐
q***92512 分钟前
Windows上安装Go并配置环境变量(图文步骤)
开发语言·windows·golang
仟濹14 分钟前
【Java 基础】面向对象 - 继承
java·开发语言
ituff25 分钟前
微软认证考试又免费了
后端·python·flask
郝学胜-神的一滴26 分钟前
Linux命名管道:创建与原理详解
linux·运维·服务器·开发语言·c++·程序人生·个人开发
2501_9416233243 分钟前
C++高性能网络服务器与epoll实战分享:大规模并发连接处理与事件驱动优化经验
开发语言·php
晚风(●•σ )1 小时前
C++语言程序设计——11 C语言风格输入/输出函数
c语言·开发语言·c++
likuolei1 小时前
XML 元素 vs. 属性
xml·java·开发语言
X***48961 小时前
C源代码生成器
c语言·开发语言
梁正雄1 小时前
2、Python流程控制
开发语言·python
catchadmin2 小时前
PHP True Async RFC 被拒——原生异步离 PHP 还有多远?
开发语言·php