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. 可以点下键到下一步
相关推荐
MasonYyp9 小时前
简单使用代码沙箱技术
python
卢锡荣9 小时前
LDR6500|超小封装 Type‑C DRP PD 控制芯片:边充边传,一芯极简,全能适配
开发语言·网络·人工智能·计算机外设·电脑
云深麋鹿9 小时前
C++ | 容器vector
开发语言·c++·容器
梨落秋霜9 小时前
Python入门篇【连接数据库】
数据库·python·oracle
格林威9 小时前
工业相机图像高速存储(C#版):直接IO存储方法,附海康相机C#实战代码!
开发语言·人工智能·数码相机·c#·工业相机·海康相机·堡盟相机
weixin_440401699 小时前
网络机器人(爬虫)+Xpath+网页F12+爬取电影Top100
爬虫·python·机器人
下雨打伞干嘛9 小时前
手写Promise
开发语言·前端·javascript
Ronin3059 小时前
【Qt常用控件】输入类控件
开发语言·qt·常用控件·输入类控件
伊甸39 小时前
Python numpy笔记01
笔记·python·数据分析
健康平安的活着9 小时前
java中事务@Transaction的正确使用和触发回滚机制【经典】
java·开发语言