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 小时前
单细胞测序分析(五)降维聚类&数据整合
linux·python·聚类·数信院生信服务器
故事不长丨2 小时前
C#定时器与延时操作的使用
开发语言·c#·.net·线程·定时器·winform
hefaxiang2 小时前
C语言常见概念(下)
c语言·开发语言
欧阳天风2 小时前
js实现鼠标横向滚动
开发语言·前端·javascript
阿桂有点桂3 小时前
C#使用VS软件打包msi安装包
windows·vscode·c#
c#上位机3 小时前
halcon图像增强之分段灰度拉伸2
c#·上位机·halcon·机器视觉
yue0083 小时前
C# Directory的用法介绍
开发语言·c#
seeyoutlb3 小时前
微服务全局日志处理
java·python·微服务
ada7_3 小时前
LeetCode(python)——148.排序链表
python·算法·leetcode·链表
雨落秋垣3 小时前
手搓 Java 的用户行为跟踪系统
java·开发语言·linq