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. 可以点下键到下一步

相关推荐

  1. Python基础知识学习

    2024-07-12 03:46:05       58 阅读
  2. python基础知识补充

    2024-07-12 03:46:05       52 阅读
  3. Python基础知识

    2024-07-12 03:46:05       38 阅读
  4. Python爬虫基础知识

    2024-07-12 03:46:05       40 阅读
  5. python基础知识(四)

    2024-07-12 03:46:05       37 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 03:46:05       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 03:46:05       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 03:46:05       58 阅读
  4. Python语言-面向对象

    2024-07-12 03:46:05       69 阅读

热门阅读

  1. Symfony 是一个用于构建PHP的框架

    2024-07-12 03:46:05       25 阅读
  2. 利用反射API时的代码注入风险与防护指南

    2024-07-12 03:46:05       18 阅读
  3. python为什么慢?(自用)

    2024-07-12 03:46:05       21 阅读
  4. F1-score

    2024-07-12 03:46:05       17 阅读