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 小时前
每日算法 -【Swift 算法】实现回文数判断!
开发语言·算法·swift
csdn_aspnet3 小时前
Java 程序求圆弧段的面积(Program to find area of a Circular Segment)
java·开发语言
EanoJiang4 小时前
C#核心
c#
佩奇的技术笔记4 小时前
Python入门手册:Python中的数据结构类型
数据结构·python
进击的_鹏5 小时前
【C++】红黑树的实现
开发语言·c++
梁下轻语的秋缘5 小时前
Python人工智能算法 模拟退火算法求解01背包问题:从理论到实践的完整攻略
人工智能·python·算法·数学建模·模拟退火算法
无心水5 小时前
【后端高阶面经:MongoDB篇】41、MongoDB 是怎么做到高可用的?
java·开发语言·mongodb·java面试·高可用·后端高阶面经·后端工程师的高阶面经
无心水5 小时前
【后端高阶面经:MongoDB篇】40、怎么优化MongoDB的查询性能?
java·开发语言·mongodb·java面试·后端高阶面经·后端工程师的高阶面经·java高阶面经
信息化未来5 小时前
python 生成复杂表格,自动分页等功能
开发语言·数据结构·python
程序猿阿伟5 小时前
《深入Python:新手易踩的语法雷区与进阶启示》
开发语言·python