python-[简单训练1]-对于输入的单词用','分开,对再输入的字母进行搜索,得到该字母出现频率最高的单词

el/2023/9/24 22:19:16

刚开始学python,应用一些简单的问题熟悉下各个基本内容

问题描述

输入多个单词,每个单词之间用英文逗号隔开,
再输入要查询的字母,得到该字母出现频率最高的单词

代码内容:

count = []
print('Please input your something : ')
message = input()
i = 0
str = ''
#将各个单词存储到列表内
for a in range(len(message)):if message[a] == ',' :count.append(str)str = ''i = i+1continueelif a == len(message)-1:str = str + message[a]count.append(str)str = str + message[a]
print(count)
print('Please input your letter : ')
x = input()
max = 0#储存该字母出现的次数
current = 0 #初始化
index= 0#储存最高次数单词的索引
for a in range(i+1):str1 = count[a]current = 0for b in range(len(str1)):if str1[b] == x :current += 1if curre

http://www.ngui.cc/el/3419052.html

相关文章

python-[简单训练2]-搜索当前文件夹所有的.txt文件,对用户输入的正则表达式进行搜索并进行显示

问题描述 打开文件夹中的所有.txt文件, 查找匹配用户提供的正则表达式的所有行, 并将结果输出在屏幕上 代码如下: import os import re d [] for filename in os.listdir(os.getcwd()):if filename.endswith(.txt):a os.path.join(os.getc…

python-[简单训练3]-搜索当前文件夹属于一类的所有文件,检查序号是否连续,不连续则修改(消除缺失的编号)

问题描述 在一个文件夹中,找到所有带指定前缀的文件,例如:spam001.txt 定位缺失的编号,让程序对后面所有的文件改名,消除缺失的编号 代码如下: import os, re, shutil cuurentdir os.getcwd() textname …

python-[openpyxl]-代码更改后

当作收藏 openpyxl模块介绍 openpyxl模块是一个读写Excel 2010文档的Python库,如果要处理更早格式的Excel文档,需要用到额外的库,openpyxl是一个比较综合的工具,能够同时读取和修改Excel文档。其他很多的与Excel相关的项目基本只…

QT-定时器QTimer 简单计时

定时器经常会用到&#xff0c;其实定时器是非常简单的&#xff0c;代码只有几个。一、创建定时器 一定要包含头文件 #include <QTimer> QTimer *Timer;然后新建即可 Timer new QTimer对定时器结束的connect connect(Timer, SIGNAL(timeout()), this, SLOT());二、一些…

python-opencv-ValueError: setting an array element with a sequence

Error描述 C:\WORK\Python\python.exe C:/Users/雪山飞狐/Desktop/研究生资料/数字图像处理/shiyan1.py Traceback (most recent call last):File "C:/Users/雪山飞狐/Desktop/研究生资料/数字图像处理/shiyan1.py", line 23, in <module>img_4 downsampling…

python-opencv-matplotlib灰度图可视化处理

参考文章1、golgotha的ttps://www.jianshu.com/p/de9013f181d7 一、Demo 一、1.热度图 利用matplotlib可视化一张图片的灰度图。 纵横坐标为图片的像素点位置(x, y),此像素点的灰度值z(x, y)当作z轴上的取值。 首先利用plot_surface分析某张图片的灰度图 import matplotli…

python-AttributeError: module 'matplotlib' has no attribute 'contourf'

错误内容 Traceback (most recent call last):File "C:/Users/雪山飞狐/Desktop/学习总结/ML100天/Code/Day_4.py", line 30, in <module>plt.contourf(X1, X2, classifer.predict(np.array([X1

(LaTex)CTex使用详细教程与资料

一份其实很短的LaTex入门文档 &#xff08;LaTex)CTex的初次使用心得及入门教程 一、 为啥子要用LaTex &#xff08;1&#xff09;待编辑文档规模尺度相关&#xff1a; 学位论文&#xff0c;书籍的编辑用LaTex就比较方便 &#xff08;2&#xff09;编号的方便&#xff1a; …

Pytorch Error:RuntimeError: Assertion cur_target 0 cur_target n_classes failed

ERROR 使用pytorch的函数 torch.nn.CrossEntropyLoss()计算Loss时报错 或者 loss criterion(output, target) 报错&#xff1a; RuntimeError: Assertion cur_target > 0 && cur_target < n_classes failed解决方法&#xff1a; 原因一&#xff1a;模型输出与…

Pytorch Error: ValueError: Expected input batch_size (324) to match target batch_size (4) Log In

ERROR 运行到loss = criterion(output, target)时 报错: ValueError: Expected input batch_size (324) to match target batch_size (4) Log In解决方法 打印 class Net(nn.Module):def __init__(se