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. 可以点下键到下一步
相关推荐
老师好,我是刘同学3 小时前
Python执行命令并保存输出到文件
python
啵啵鱼爱吃小猫咪5 小时前
机械臂阻抗控制github项目-mujoco仿真
开发语言·人工智能·python·机器人
似水明俊德5 小时前
02-C#
开发语言·c#
MaximusCoder5 小时前
等保测评命令——Centos Linux
linux·运维·经验分享·python·安全·centos
yunyun321235 小时前
用Python生成艺术:分形与算法绘图
jvm·数据库·python
m0_662577975 小时前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
oem1105 小时前
C++中的享元模式实战
开发语言·c++·算法
songyuc6 小时前
【PyTorch】感觉`CrossEntropyLoss`和`BCELoss`很类似,为什么它们接收labels的shape常常不一样呢?
人工智能·pytorch·python
似水明俊德6 小时前
01-C#.Net-泛型-面试题
java·开发语言·面试·c#·.net
ℳ๓₯㎕.空城旧梦6 小时前
Python单元测试(unittest)实战指南
jvm·数据库·python