书生大模型实战营(第三期)-L0:Python

任务概览

任务类型任务内容
闯关任务Python实现wordcount
闯关任务Vscode连接InternStudio debug笔记

一、Python实现wordcount

def wordcount(text):
    # 将字符串转为小写,去除标点符号,并分割成单词列表
    import re
    words = re.findall(r'\b\w+\b', text.lower())
    
    # 统计每个单词出现的次数
    word_count = {}
    for word in words:
        if word in word_count:
            word_count[word] += 1
        else:
            word_count[word] = 1
    
    return word_count

# 示例输入
text = """Hello world!  
This is an example.  
Word count is fun.  
Is it fun to count words?  
Yes, it is fun!"""

# 调用wordcount函数并打印结果
result = wordcount(text)
print(result)

二、Vscode连接InternStudio debug

通过SSH连接InternStudio的开发机。

为开发机安装Python插件,用于debug。(只需要安装合适版本Python即可,根据我个人经验,安装较为老一点的版会更好,当然这个平台安装最新的没有出现什么问题)

 接下来就可以打断点了,但是打断点前确保代码没有问题,可以如下图运行代码:

 能顺利运行,接下来打一个断点,如图:

debug效果如图:

 

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值