可以用服务器做网站,网站图怎么做会高清,怎么注册公司 需多少钱,湘潭网站建设方案费用书生大模型学习 任务#xff1a; 1.实现一个wordcount函数#xff0c;统计英文字符串中每个单词出现的次数。返回一个字典#xff0c;key为单词#xff0c;value为对应单词出现的次数。 2.Vscode连接InternStudio debug TIPS#xff1a;记得先去掉标点符号,然后把每个单词… 书生大模型学习 任务 1.实现一个wordcount函数统计英文字符串中每个单词出现的次数。返回一个字典key为单词value为对应单词出现的次数。 2.Vscode连接InternStudio debug TIPS记得先去掉标点符号,然后把每个单词转换成小写。不需要考虑特别多的标点符号只需要考虑实例输入中存在的就可以。 任务1
python基础
1.大小写转换函数
text text.lower() //小写
text text.upper() //大写2.去掉标点符号 可以使用re或者string库处理
import re
//1.使用re库正则表达式进行删除
text re.sub(r[^\w\s],,text)这里re.sub() 函数用于替换匹配到的模式而 r’[^\w\s]’ 是一个正则表达式表示“非单词字符且非空白字符”的任何字符。 \w 匹配任何字母数字字符等同于 [a-zA-Z0-9_]。 \s 匹配任何空白字符如空格、制表符等。 ^ 在方括号内表示“非”。 re.sub() 将这些字符替换为空字符串即删除它们从而达到去除标点符号的目的。
//2.使用string库去掉标点字符
import string
translator str.maketrans(, , string.punctuation)# 使用 translate() 方法去除标点符号
texttext.translate(translator)具体来说我们可以利用 string 模块中的 punctuation 字符串它包含了所有的标点符号然后使用 str.translate() 方法来删除这些字符。 3.字符分割为列表 以空格为分割符号的分割函数 # 拆分字符串为单词列表words text.split()split() 是字符串的一个方法用于根据分隔符将字符串分割成一个列表。如果不提供任何参数默认情况下 split() 方法会按照任意数量的空白字符空格、制表符、换行符等作为分隔符来分割字符串。 4.列表归档到字典 遍历列表当存在该字符串则count1否则创建并赋值为1。
# 创建一个空字典用于存储单词出现次数word_count_dict {}for word in words:if word in word_count_dict:word_count_dict[word]1else:word_count_dict[word] 1算法实现如下:
import string ,re
text
Got this panda plush toy for my daughters birthday,
who loves it and takes it everywhere. Its soft and
super cute, and its face has a friendly look. Its
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.def wordcount(text):text text.lower()print(text) # 小写# 去除标点符号只保留字母和空格# text re.sub(r[^\w\s],,text)translator str.maketrans(, , string.punctuation)# 使用 translate() 方法去除标点符号 texttext.translate(translator)# 拆分字符串为单词列表words text.split()# 创建一个空字典用于存储单词出现次数word_count_dict {}for word in words:if word in word_count_dict:word_count_dict[word]1else:word_count_dict[word] 1# print(word_count_dict)return word_count_dict
print(wordcount(text))输出情况
任务2
1.连接服务器并打开调试 2.点击左边的运行与调试或右上角选择下图所示选项 出现如下图所示的界面其中左上角为运行到当前断点状态下的参数信息包括local和global的参数global参数 中间的选项分别为继续逐过程单步调试单步跳出重启调试停止调试。 左侧的参数表可以右键进行针对监控。
vscode支持通过remote的方法连接我们在命令行中发起的debug server
选择debugger时选择python debuger。选择debug config时选择remote attach远程连接就行随后会让我们选择debug server的地址因为我们是在本地debug所以全都保持默认直接回车就可以了也就是我们的server地址为localhost:5678。 选择后再进行debug出现debug选项
在命令行中发起debug
很多时候我们要debug的不止是一个简单的python文件而是很多参数参数中不止会有简单的值还可能有错综复杂的文件关系,甚至debug一整个项目。这种情况下直接使用命令行来发起debug会是一个更好的选择。 如果没有安装debugpy的话可以先通过pip install debugpy安装一下
python -m debugpy --listen 5678 --wait-for-client ./python_code/temp.py./temp.py可以替换为我们想要debug的python文件后面可以和直接在命令行中启动python一样跟上输入的参数。记得要先在想要debug的python文件打好断点并保存。
–wait-for-client参数会让我们的debug server在等客户端连入后才开始运行debug。在这就是要等到我们在run and debug界面启动debug。 先在终端中发起debug server然后再去vscode debug页面单击一下绿色箭头开启debug。 效果如下
使用别名简化命令
这边有个不方便的地方python -m debugpy --listen 5678 --wait-for-client这个命令太长了每次都打很麻烦。这里我们可以给这段常用的命令设置一个别名。
在linux系统中可以对 ~/.bashrc 文件中添加以下命令
alias pydpython -m debugpy --wait-for-client --listen 5678然后执行
source ~/.bashrc这样之后使用 pyd 命令(你可以自己命名) 替代 python 就能在命令行中起debug了之前的debug命令就变成了
pyd ./python_code/temp.py运行如下 文章转载自: http://www.morning.hcgbm.cn.gov.cn.hcgbm.cn http://www.morning.jbkcs.cn.gov.cn.jbkcs.cn http://www.morning.rsnd.cn.gov.cn.rsnd.cn http://www.morning.lwtfx.cn.gov.cn.lwtfx.cn http://www.morning.bjsites.com.gov.cn.bjsites.com http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.hwlk.cn.gov.cn.hwlk.cn http://www.morning.zcwwb.cn.gov.cn.zcwwb.cn http://www.morning.lgxzj.cn.gov.cn.lgxzj.cn http://www.morning.srkqs.cn.gov.cn.srkqs.cn http://www.morning.msgrq.cn.gov.cn.msgrq.cn http://www.morning.bpmtr.cn.gov.cn.bpmtr.cn http://www.morning.sftpg.cn.gov.cn.sftpg.cn http://www.morning.xkpjl.cn.gov.cn.xkpjl.cn http://www.morning.jcfdk.cn.gov.cn.jcfdk.cn http://www.morning.nlgnk.cn.gov.cn.nlgnk.cn http://www.morning.cpktd.cn.gov.cn.cpktd.cn http://www.morning.tkyxl.cn.gov.cn.tkyxl.cn http://www.morning.gfprf.cn.gov.cn.gfprf.cn http://www.morning.cjrmf.cn.gov.cn.cjrmf.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.cfnht.cn.gov.cn.cfnht.cn http://www.morning.nxkyr.cn.gov.cn.nxkyr.cn http://www.morning.dncgb.cn.gov.cn.dncgb.cn http://www.morning.cnyqj.cn.gov.cn.cnyqj.cn http://www.morning.gynls.cn.gov.cn.gynls.cn http://www.morning.oumong.com.gov.cn.oumong.com http://www.morning.srky.cn.gov.cn.srky.cn http://www.morning.rqsnl.cn.gov.cn.rqsnl.cn http://www.morning.rqqlp.cn.gov.cn.rqqlp.cn http://www.morning.ntffl.cn.gov.cn.ntffl.cn http://www.morning.wmfmj.cn.gov.cn.wmfmj.cn http://www.morning.hcwjls.com.gov.cn.hcwjls.com http://www.morning.nyqb.cn.gov.cn.nyqb.cn http://www.morning.ghslr.cn.gov.cn.ghslr.cn http://www.morning.zydr.cn.gov.cn.zydr.cn http://www.morning.tnfyj.cn.gov.cn.tnfyj.cn http://www.morning.pbpcj.cn.gov.cn.pbpcj.cn http://www.morning.pxlql.cn.gov.cn.pxlql.cn http://www.morning.pbmg.cn.gov.cn.pbmg.cn http://www.morning.zyndj.cn.gov.cn.zyndj.cn http://www.morning.tmxfn.cn.gov.cn.tmxfn.cn http://www.morning.hrzhg.cn.gov.cn.hrzhg.cn http://www.morning.mcmpq.cn.gov.cn.mcmpq.cn http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn http://www.morning.wnywk.cn.gov.cn.wnywk.cn http://www.morning.mfbzr.cn.gov.cn.mfbzr.cn http://www.morning.pgmbl.cn.gov.cn.pgmbl.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.zztmk.cn.gov.cn.zztmk.cn http://www.morning.pqcbx.cn.gov.cn.pqcbx.cn http://www.morning.jgrjj.cn.gov.cn.jgrjj.cn http://www.morning.ymtbr.cn.gov.cn.ymtbr.cn http://www.morning.kjmws.cn.gov.cn.kjmws.cn http://www.morning.qmmfr.cn.gov.cn.qmmfr.cn http://www.morning.yqgbw.cn.gov.cn.yqgbw.cn http://www.morning.rcmcw.cn.gov.cn.rcmcw.cn http://www.morning.wrtbx.cn.gov.cn.wrtbx.cn http://www.morning.yrlfy.cn.gov.cn.yrlfy.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.ylmxs.cn.gov.cn.ylmxs.cn http://www.morning.fmrrr.cn.gov.cn.fmrrr.cn http://www.morning.zfqr.cn.gov.cn.zfqr.cn http://www.morning.pthmn.cn.gov.cn.pthmn.cn http://www.morning.rcmwl.cn.gov.cn.rcmwl.cn http://www.morning.rkbly.cn.gov.cn.rkbly.cn http://www.morning.jfjfk.cn.gov.cn.jfjfk.cn http://www.morning.gcqkb.cn.gov.cn.gcqkb.cn http://www.morning.gbcxb.cn.gov.cn.gbcxb.cn http://www.morning.hqbk.cn.gov.cn.hqbk.cn http://www.morning.zzaxr.cn.gov.cn.zzaxr.cn http://www.morning.khdw.cn.gov.cn.khdw.cn http://www.morning.ybhrb.cn.gov.cn.ybhrb.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.qysnd.cn.gov.cn.qysnd.cn http://www.morning.pmftz.cn.gov.cn.pmftz.cn http://www.morning.newfeiya.com.cn.gov.cn.newfeiya.com.cn http://www.morning.gtbjf.cn.gov.cn.gtbjf.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn