Python基础100题打卡Day21

【华为OD机试E卷真题】 优秀学员统计 | 原题+思路+多语言代码(本题100%)(C++、Java、Py) 华为OD机试E卷真题 优秀学员统计 | 原题+思路+多语言代码(本题100%)(C++、Java、Py) 阅读详情

题目八十五

使用列表理解,请在[12,24,35,70,88,120,155]中删除第0,4,5位数字后,编写一个打印列表的程序。

代码实现

方法一:
1.使用for循环
2.使用if条件判断

lst = [12,24,35,70,88,120,155]
lst1 = []
for i in range(len(lst)):
    if (i!=0) and  (i!=4) and (i!=5):
        lst1.append(lst[i])

print(lst1)

方法二:
1.列表的循环创建

lst = [12,24,35,70,88,120,155]
lst1 = [lst[i] for i in range(len(lst)) if i not in (0,4,5)]
print(lst1)

运行结果

[24, 35, 70, 155]

题目八十六

通过使用列表理解,请在删除[12,24,35,24,88,120,155]中的值24之后,编写一个打印列表的程序。

代码实现

1.列表的中remove函数的使用

lst = [12,24,35,24,88,120,155]
lst1 = lst.remove(24)
print(lst)

运行结果

[12, 35, 24, 88, 120, 155]

题目八十七

对于两个给定的列表[1,3,6,78,35,55]和[12,24,35,24,88,120,155],编写一个程序来生成一个列表,其元素是上述给定列表的交集。

提示:
使用set()和“&=”执行SET交叉操作。

代码实现

方法一:
1.使用循环判断,当元素相同时,进行输出

lst1 = [1,3,6,78,35,55]
lst2 = [12,24,35,24,88,120,155]
lst3 = []
for i in lst1:
    for j in lst2:
        if i==j:
            lst3.append(i)

print(lst3)

方法二:
使用set函数的"&"操作

lst1 = [1,3,6,78,35,55]
lst2 = [12,24,35,24,88,120,155]
set1 = set(lst1)
set2 = set(lst2)
lst3 = set1 & set2
print(lst3)

方法三:
使用set.intersection()求解集合的交

lst1 = [1,3,6,78,35,55]
lst2 = [12,24,35,24,88,120,155]
set1 = set(lst1)
set2 = set(lst2)
lst3 = set.intersection(set1, set2)
print(lst3)

运行结果

{35}

题目八十八

对于给定的列表[12,24,35,24,88,120,155,88,120,155],在删除保留原始顺序的所有重复值之后,编写一个打印此列表的程序。

提示:
使用set()存储许多值而不重复。

代码实现

方法一:
1.使用set()函数,将列表转成集合变量,去除相同元素
2.将集合转成列表

lst = [12,24,35,24,88,120,155,88,120,155]
lst1 = list(set(lst))
print(lst1)

方法二:
1.利用列表中lst.count(i)统计次数
2.利用列表中lst.remove(i)去除元素

lst = [12,24,35,24,88,120,155,88,120,155]
for i in lst:
    if lst.count(i) > 1 :
        lst.remove(i)

print(lst)

运行结果

[12, 35, 24, 88, 120, 155]

题目八十九

定义类Person及其两个子类:男性和女性。所有的类都有一个方法“getGender”,它可以打印“Male”代表Male class,“Female”代表Female class。

代码实现

class Person():   #定义父类,括号内有没有Object,都默认作为父类
    def getGender(self):  #父类的行为
        return "Unknow"

class Male(Person):  #定义第一个子类,括号内的是选择继承的父类
    def getGender(self):
        return "Male"

class Female(Person):  #定义第二个子类,括号内的是选择继承的父类
    def getGender(self):
        return "Female"

aMale = Male()
aFemale = Female()
print(aMale.getGender())
print(aFemale.getGender())

运行结果

Male
Female
python打卡DAY21 print('shap_values[0,:,:]shape',shap_values[0,:,:].shape)##这里也可以省略后面的写作shap_values[0】,代表第一个样本所有特征对所有类别的贡献,后面部位可以省略但是前面不能。# print(f'k={k}\n 惯性:{kmeans.inertia_:.2f}\n轮廓系数:{silhouette:.3f}\n CH系数:{ch:.2f}\n DB{db:.3f}') 阅读详情

相关推荐

用Verilog搭出RISC-V架构单周期CPU

这是笔者学校暑期学期的必修课,难度并不高(仅追求及格的话),但相当耗时,对于在硬件设计方面完全不感冒的同学更是一场避不开的折磨,所以笔者想通过自己的成果和被折磨经验来帮助有此方面需求的同学,或是对于CPU设计有浓厚兴趣的人。

paticita的博客 1万+

python暑期训练100题

python暑期训练100题(附答案)

Algernon98的博客 2293

帕塞瓦尔定理(Parseval‘s theorem)的证明

帕塞瓦尔定理(Parseval's theorem)表明了信号在时域和频域上的能量相等。

weixin_42428226的博客 2万+

Python零基础编程【76-100】题

本专栏主要涉及到100道Python零基础编程题,大部分题型翻译于Github上的100+ Python challenging programming exercises,如果小伙伴对于英语没有阅读障碍,可以去Github上阅读。专栏共有100题,分为四章,每章25道题;本篇博客为Python零基础编程的第四篇【76-100】;好了,废话不多说,开始展开; 第一篇:Python零基础编程【1-25】题 第二篇:Python零基础编程【26-50】题 第三篇:Python零基础编程【51-75】题

qq_38230663的博客 944

在AutoDL的A100云服务器上,用Docker搞定Sapien+RobotWin环境(附完整conda list)

本文详细介绍了在AutoDL的A100云服务器上使用Docker构建Sapien+RobotWin环境的完整指南。通过配置Vulkan渲染管线、精确复现Conda环境以及解决常见问题,帮助研究人员高效搭建稳定的机器人仿真开发环境,特别适合需要高性能GPU加速的复杂仿真任务。

weixin_30689307的博客 430

[附源码]计算机毕业设计-Steam游戏平台系统论文Springboot程序

项目运行环境配置:(Webstorm也行)+ Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)。项目技术:等等组成,B/S模式 + Maven管理等等。环境需要1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可4.

JSP、ssm毕设程序源码 1494

Python编写程序,生成一个整型列表,输出包含原列表中所有元素的新列表、包含原列表中所有元素的逆序列表,以及输出具有偶数位置的元素列表。

源代码: #编写程序,生成一个整型列表,输出包含原列表中所有元素的新列表、包含原列表中所有元素的逆序列表,以及输出具有偶数位置的元素列表。 import random x=[] for i in range(20): x.append(random.randint(0,100))#将随机生成的元素加入到列表中,构成随机列表 x1=x print('随机生成的列表为',x) x.reverse()#列表进行逆序 print('逆序后的列表',x) #x1=sorted(x,reverse=True)#

weixin_52924358的博客 2975

第6篇:ESP32连接无源喇叭播放音乐《涛声依旧》

相邻两个音之间的倍数是2^(1/12),约等于1.0594630943592952645618252949463)。这样一来,高八度的do频率是低八度do的两倍。我们把频率440赫兹作为中央C ,C调的歌就是把频率440赫兹当作do,乐谱中写作:1=C。一个八度分成12份,八个八度的十二平均音率对应的频率如下(从33Hz到7902Hz)。相邻的两个音之间的差一个半音,12345671之间的间隔分别是“全全半全全全半”。D调的歌就是把从440后面第二个音494赫兹当作do,乐谱中写作1=D。

Txwtech 1420

python的列表生成式和字典生成式

列表生成式 1. 什么是列表生成式 列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式 列表生成式也可以叫做列表解析 列表生成式的格式:[expression for i in 序列 if…]==表达式+循环+条件 一般情况下循环太繁琐,而列表生成式则可以用一行语句代替多行循环生成列表 运用列表生成式,可以写出非常简洁的代码 运用列...

weixin_45029822的博客 932

Python 爬虫教程:企业官网基本信息抓取

本文介绍了使用Python爬虫技术抓取企业官网信息的方法,包括公司名称、简介、联系方式、地址、产品及新闻等数据。通过Requests和BeautifulSoup库实现网页请求与解析,并利用Pandas存储数据为CSV文件。同时提供了应对反爬虫机制(如设置User-Agent、代理IP池、延迟请求等)的解决方案,帮助高效获取企业公开数据。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1859

【异常】安装hermes-agent时Git克隆大仓库报错:error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CAN

摘要:本文分析了Ubuntu服务器执行Git递归克隆时出现的网络传输中断错误(HTTP/2流异常关闭、数据截断)。主要原因是网络限制、协议兼容问题和缓冲区不足。提供了四种解决方案:1)扩大Git HTTP缓冲区;2)切换为HTTP/1.1协议;3)采用浅克隆+分步拉取子模块;4)网络优化措施。重点推荐浅克隆分步拉取作为最有效方案,所有方法无需重启即可生效,可快速解决大仓库递归克隆失败问题。

奶爸的编程之路,也就一周冷个三天 668

生成一个列表,列表元素为: [1**2,2**2,3**2,4**2、、、、n**2]

题目10:生成一个列表,列表元素为: [12,22,32,42、、、、n2]** li=[] for i in range(1,8): li.append(i**2) print (li)

后街女孩的博客 912

影楼精修-AI追色算法解析

本文解析了像素蛋糕软件中AI追色功能的技术原理与实现方案,为理解AI追色技术提供了实用参考。

Trent1985的专栏 2万+

Python基础100题打卡Day6

题目十八 网站要求用户输入用户名和密码才能注册。编写一个程序来检查用户输入的密码的有效性。 以下是检查密码的标准: 至少有一个大写字母 至少有一个小写字母 至少有一个数字 至少有[$#@]中的一个特殊符号 长度至少为6 长度至多为12 程序能够对以逗号相隔的密码输入时进行检测,并将符合条件的密码输出。 比如以下列作为输入: ABd1234@1,a F1#,2w3E*,2We3345 则输出为: ABd1234@1 代码实现 方法一 def up_check(x): for i in x:

ProjectJ的博客 856

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

python打卡训练营打卡记录day22

核心影响特征Sex(性别)是决定生存概率的最关键因素,女性更易生存;Fare(票价)高、Age(年龄)小也显著促进生存。客舱等级矛盾Pclass高(舱位等级低,如 3 级舱)反而可能抑制生存,与常识中 “高舱位更易生存” 看似矛盾,需结合数据具体分布进一步验证(如高舱位是否有更多特殊情况)。家庭关系影响弱SibSp(兄弟姐妹 / 配偶数)、Parch(父母 / 子女数)对生存影响较小,仅在特定值时表现出一定规律。@浙大疏锦行。

yorushika_的博客 1542

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Python基础100题打卡Day10

题目三十一 定义一个函数,它可以打印一个字典,其中键是介于1到20之间的数字(都包括在内),值是键的平方。 代码实现 def dic(): dic = {i:i**2 for i in range(1,21)} print(dic) dic() 运行结果 输出结果: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100, 11: 121, 12: 144, 13: 169, 14: 196, 15: 22

ProjectJ的博客 813

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

day 21 python打卡

仔细回顾一下之前21天的内容,没跟上进度的同学补一下进度。

2503_91756091的博客 175

推荐GitHub上100天学习Python的开源项目

点击上方“程序IT圈”,选择“置顶公众号”每天早晨8点50分,准点开车打卡来自:开源最前线综合自:https://github.com/jackfrued/Python-...

6115

Day3 python打卡

列表的基础操作。

m0_74197500的博客 598

百人计划-21天python打卡

这里我会放一些我在打卡过程中遇到的一些小问题 问题1:在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息:SyntaxError: Non-ASCII character ‘\xe5’ in file ******* 原因:python的默认编码文件是用的ASCII码,你将文件存成了UTF-8 解决方法:在文件开头加上# -- coding: UTF-8 -- 或者 #coding=utf-8 问题2:Mac升级后一直提示/usr/bin/env:python:No such f.

wanyu_的博客 1129

Python打卡5.21(day22)

自行学习参考如何使用kaggle平台,写下使用注意点,并对下述比赛提交代码。仔细回顾一下之前21天的内容,没跟上进度的同学补一下进度。

qq_56657939的博客 261

【21天python打卡】第8天 基础技能(1)

​大家好,今天是21天python打卡的第8天,讲了如何创建python如何创建类,抽象类,访问限制的说明。今天说说python的相关技能,比如将时间日期的处理,数据文件的读写,以及数据库的简单操作。​学习的最大理由是想摆脱平庸,早一天就多一份人生的精彩;迟一天就多一天平庸的困扰。...

爱吃饼干的小白鼠的博客 860

100天学Python,从菜鸟到大佬!

Linux基础命令Linux中的实用程序Linux的文件系统Vim编辑器的应用环境变量和Shell编程软件的安装和服务的配置网络访问和管理其他相关内容Day36~40 -数据库基础和进阶关系型数据库MySQLNoSQL入门Day41~55 - 实战DjangoDay56~60 - 实战Flask。

Trb601012的博客 1685

Day22 Python打卡训练营

自行学习参考如何使用kaggle平台,写下使用注意点,并对下述比赛提交。仔细回顾一下之前21天的内容,没跟上进度的同学补一下进度。

2503_90248820的博客 292

100天学Python, 从菜鸟到大佬!

Linux基础命令Linux中的实用程序Linux的文件系统Vim编辑器的应用环境变量和Shell编程软件的安装和服务的配置网络访问和管理其他相关内容Day36~40 -数据库基础和进阶关系型数据库MySQLNoSQL入门。

2401_86168842的博客 1634
上一篇: Python基础100题打卡Day20
下一篇: Python基础100题打卡Day22
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值