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. 可以点下键到下一步
相关推荐
難釋懷2 分钟前
Lua语法入门-条件控制、函数
开发语言·junit·lua
桌面运维家13 分钟前
Win10打印机共享故障排查:权限与网络配置详解
开发语言·网络·php
Sunshine for you1 小时前
实时操作系统中的C++
开发语言·c++·算法
史蒂芬_丁1 小时前
C++深度拷贝例子
java·开发语言·c++
数据科学小丫1 小时前
Python 数据存储操作_数据存储、补充知识点:Python 与 MySQL交互
数据库·python·mysql
Knight_AL1 小时前
Nacos 启动问题 Failed to create database ’D:\nacos\nacos\data\derby-data’
开发语言·数据库·python
leiming62 小时前
CAN 通信协议学习讲义(带图文 + C 语言代码)
c语言·开发语言·学习
xht08322 小时前
PHP vs C语言:核心差异全解析
c语言·开发语言·php
yoothey2 小时前
Java字节流与字符流核心笔记(问答+考点复盘)
java·开发语言·笔记
查古穆3 小时前
python进阶-Pydantic模型
开发语言·python