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. 可以点下键到下一步
相关推荐
wenlonglanying几秒前
Windows安装Rust环境(详细教程)
开发语言·windows·rust
2401_846341651 分钟前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
未知鱼11 分钟前
Python安全开发之子域名扫描器(含详细注释)
网络·python·安全·web安全·网络安全
2401_8318249614 分钟前
编写一个Python脚本自动下载壁纸
jvm·数据库·python
CQU_JIAKE17 分钟前
3.21【A】
开发语言·php
2401_8579182925 分钟前
Python在2024年的主要趋势与发展方向
jvm·数据库·python
今儿敲了吗27 分钟前
python基础学习笔记第九章——模块、包
开发语言·python
xyq202433 分钟前
TypeScript 命名空间
开发语言
2301_8101609536 分钟前
C++与物联网开发
开发语言·c++·算法
sxlishaobin39 分钟前
Java I/O 模型详解:BIO、NIO、AIO
java·开发语言·nio