Python基础学习笔记:字典(Dictionary)的(增、删、改、查)教程

Python基础学习笔记:字典(Dictionary)的(增、删 书籍的好处就在于权威和体系健全,刚开始学习的时候你可以只看视频或者听某个人讲课,但等你学完之后,你觉得你掌握了,这时候建议还是得去看一下书籍,看权威技术书籍也是每个程序员必经之路。Python所有方向路线就是把Python常用的技术点做整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。成为一个Python程序员专家或许需要花费数年时间,但是打下坚实的基础只要几周就可以,如果你按照我提供的学习路线以及资料有意识地去实践,你就有很大可能成功! 阅读详情

字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值 key=>value 对用冒号:分割,每个键值对之间用,分割,整个字典包括在花括号 {} 中,格式如下所示:

d = {
   
   key1 : value1, key2 : value2 }

键一般是唯一的,如果重复最后的一个键值对会替换前面的,值不需要唯一。值可以取任何数据类型,但键必须是不可变的,如字符串,数字或元组。

1.访问字典里的值

把相应的键放入熟悉的方括弧,如下实例:

dict = {
   
   '姓名': '小明', '年龄': 18, '班级': '1班'}

print("姓名:", dict['姓名'])
print("年龄: ", 
Python基础学习之字典(Dictionary) 文章目录1、什么是字典2、创建字典3、查询字典中的值4、增加字典关键字与值5、更新字典中的值5、删除字典元素6、排序7、字典函数8、字典方法 1、什么是字典 说到字典,就让我想到上小学的时候看过的字典《中华字典》,只要查一下部首或拼音就能够查到相应字的说明。但他是多对一的,但今天所要说的Python字典(dic)他是一对一的。 他就像身份证的编码与人的姓名一样,身份证编号是唯一的,人名可以重... 阅读详情

相关推荐

Python教程之字典(Dictionary)操作详解

Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串、数字、元组等其他容器模型。

2301_80240808的博客 1149

Python 字典(Dictionary)

字典是另一种可变容器模型,且可存储任意类型对象。字典的每个键值 key:value 对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中 ,格式如下所示:dict 作为 Python 的关键字和内置函数,变量名不建议命名为。键一般是唯一的,如果重复最后的一个键值对会替换前面的,值不需要唯一。'3'值可以取任何数据类型,但键必须是不可变的,如字符串,数字或元组。

xiaoaque的博客 1011

在Python中如何向字典中添加新的内容

有时候,我们需要向字典中添加新的键值对,以便扩展字典的功能。在本篇文章中,我将详细介绍如何使用Python向字典中添加新的内容。方法接受一个字典作为参数,将该字典中的键值对添加到原始字典中。使用赋值操作符(=)是一种向字典中添加新的键值对的简单方法。最后,我们打印了字典的内容,可以看到新的键值对已成功添加到字典中。最后,我们打印了字典的内容,可以看到新的键值对已成功添加到字典中。然后,使用赋值操作符(=)向字典中添加了两个新的键值对。如果我们需要向字典中添加多个键值对,可以使用字典的。

DarcyCode的博客 2234

【Python3教程】Python3基础篇之Dictionary(字典)

在Python中,字典(Dictionary)是一种可变容器模型,它能够存储任意类型对象,如整数、字符串、浮点数、元组、列表、字典等,并且这些对象是通过键(key)来访问的,而不是通过索引。字典中的每个元素都是一个键值对(key-value pair),键和值通过冒号(:)分隔,并且每个键值对之间用逗号(,)分隔,整个字典包含在花括号({})中。

No8g攻城狮的博客 1073

在Rviz仿真环境中搭建传送带

<geometry><material>

qq_58268456的博客 947

【智能体】零代码实战:Coze多智能体协作开发全流程解析

本文详细解析了Coze平台的多智能体协作开发全流程,从入门指南到实战技巧,帮助用户零代码构建高效AI团队。通过模块化设计和专业分工,多智能体系统能显著提升任务处理速度和准确率,适用于客服、内容创作、教育培训等多个场景。文章还提供了性能优化和常见问题解决方案,助力开发者快速掌握Multi-Agent技术。

weixin_29239279的博客 342

知识的定义与分类体系详解 - 从零基础到专业理解

知识的定义与分类体系详解 - 从零基础到专业理解

engchina的专栏 4420

维修电工必看:CODESYS最新版汉化安装与禾川PLC配置全流程(附常见问题解决)

本文详细介绍了CODESYS最新版的汉化安装与禾川PLC配置全流程,包括软件下载地址、安装步骤、汉化设置、硬件连接配置及常见问题解决方案。适合维修电工和自动化工程师快速掌握工业自动化开发环境,提升工作效率。

weixin_26897585的博客 456

【Matlab】如何使用Simulink进行电池建模和SOC预估

“通过Simulink电池建模进行SOC预估,其实挺容易!” 1 声明 本文只描述一般性电池建模方法,文中出现的电池相关数据来自一些论文或者外文文献,对数据的真实性不做任何保证。 本文参考了不少国内高校的硕士论文和外文文献,所以本篇文章只作为学术性交流,未经...

wanff1204的博客 2万+

【YOLOv11】006、YOLOv11数据增强策略:Mosaic、MixUp等增强技术原理解析

摘要:YOLOv11在产线缺陷检测中遇到小尺寸瑕疵漏检问题,暴露了训练数据过于"干净"的缺陷。数据增强的核心是提升模型泛化能力,而非简单扩充数据。Mosaic增强通过多图拼接迫使模型处理多尺度目标,需注意边界框裁剪细节;MixUp通过线性插值使决策边界更平滑,但需避免类别冲突。自适应增强策略应随训练进度动态调整强度。实际应用中,需针对小目标、类别不平衡等场景调整增强参数,并确保验证与推理流程一致。数据增强应针对性解决具体问题,而非盲目尝试组合。

企鹅码农的专属播客,分享10多年的实战案例和经验解读,包含YOLO、RT-DETR、AI等各个工作领域。 374

ADAS工作原理解析:如何通过智能技术提升驾驶安全

ADAS通过集成传感器、摄像头、雷达、SoC计算单元以及高效的数据融合技术,提供了一系列主动和被动安全功能,如自动刹车、车道保持、自适应巡航控制等。这些功能共同作用,不仅减少了交通事故的发生,还大幅提升了驾驶员的驾驶体验和安全性。随着技术的进步,ADAS的功能将越来越智能,最终迈向全自动驾驶的未来🚗💨。

weixin_43199439的博客 1158

Linux:安装Debian最新10.x操作系统(超详细)

安装Debian最新10.x操作系统安装Debian最新10.x操作系统1.下载Debian镜像2. 镜像安装引导启动页面,选择图形化安装:选择语言、时区,选中后点击continue:选择键盘模式:配置Hostname主机名,设置Root密码创建普通用户名和密码,进入磁盘分区步骤,选择“所有文件放在同一个分区”确认分区信息磁盘配置完,进入软件安装模块:选择源:进入软件包配置,等待配置结束根据需要选择软件包安装3. 安装完成重启后登录使用 安装Debian最新10.x操作系统 1.下载Debian镜像 下载D

HowieXue 薛永浩的博客 3万+

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 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")

上一篇: Python基础学习笔记:元组(Tuple)
下一篇: Python基础学习笔记:函数教程 一篇文章让你掌握python函数
Python程序u猿
博客等级 码龄5年 624粉丝 84原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址