当前位置:网站首页>list和dict的应用
list和dict的应用
2022-06-12 12:50:00 【plzdonotlietome】
1. list列表扩展的方式有几种(或者说添加元素的方法)
extend:通过迭代追加来扩展元素


insert:在索引前插入对象

append:追加到末尾

2. 对["cherry", "litchi", "strawberry", "mangosteen", "pomelo", "pineapple", "pitaya", "durian"]进行默认排序和使用第三个字母进行排序

3. dict中所有方法的使用(先写源代码再写样例)
clear(self): # real signature unknown; restored from __doc__
""" D.clear() -> None. Remove all items from D. """
删除所有项目

opy(self): # real signature unknown; restored from __doc__
""" D.copy() -> a shallow copy of D """
浅拷贝

get(self, *args, **kwargs): # real signature unknown
""" Return the value for key if key is in the dictionary, else default. """
如果 key 在字典中,则返回 key 的值,否则返回默认值

items(self): # real signature unknown; restored from __doc__
""" D.items() -> a set-like object providing a view on D's items "
一个类似集合的对象,提供字典项目的视图


keys(self): # real signature unknown; restored from __doc__
""" D.keys() -> a set-like object providing a view on D's keys ""
一个类似集合的对象,提供 字典键上的视图

pop(self, k, d=None): # real signature unknown; restored from __doc__
"""
D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
删除指定的键并返回相应的值

If key is not found, default is returned if given, otherwise KeyError is raised
如果未找到 key,则返回 default(如果给定),否则引发 KeyError


popitem(self, *args, **kwargs): # real signature unknown
"""
Remove and return a (key, value) pair as a 2-tuple.
删除(键、值)对并将其作为 二元组返回。

Pairs are returned in LIFO (last-in, first-out) order.
成对按后进先出(后进先出)顺序返回
Raises KeyError if the dict is empty.
如果字典为空,则引发 KeyErro
setdefault(self, *args, **kwargs): # real signature unknown
"""
Insert key with a value of default if key is not in the dictionary.
如果键不在字典中,则插入值为默认值的键。

Return the value for key if key is in the dictionary, else default.
"""如果 key 在字典中,则返回 key 的值,否则返回默认值。

update(self, E=None, **F): # known special case of dict.update
"""
D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
从字典/可迭代 E 和 F 更新 D


If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
如果 E 存在并且具有 .keys() 方法,则对于 E 中的 k:D[k] = E[k]
If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
如果 E 存在并且缺少 .keys() 方法,则对于 E 中的 k, v:D[k] = v
In either case, this is followed by: for k in F: D[k] = F[k]
在任何一种情况下,这后面跟着:对于F中的k:D[k] = F[k]
values(self): # real signature unknown; restored from __doc__
""" D.values() -> an object providing a view on D's values """
在任何一种情况下,这后面跟着:对于F中的k:D[k] = F[k]

边栏推荐
- Newton method for solving roots of polynomials
- itk itk::BSplineDeformableTransform
- 机械臂雅可比矩阵IK
- 数组——二维数组的花式遍历技巧
- From simple to deep - websocket
- itk itk::BSplineDeformableTransform
- The 4th Zhejiang CTF preliminary contest web pppop
- Online picture material
- STM32F1与STM32CubeIDE编程实例-设备驱动-DHT11温度温度传感器驱动
- Jacobian matrix IK of manipulator
猜你喜欢

442 authors, 100 pages! It took Google 2 years to release the new benchmark big bench | open source

Embedded driver design

构建嵌入式系统软件开发环境-建立交叉编译环境

机械臂改进的DH参数与标准DH参数理论知识

Buu question brushing record - 4

Online picture material

leetcode 47. Permutations II 全排列 II(中等)
![[EDA] chip layout design: VLSI layout design using electric](/img/a1/da0739070c940b36bc7a55d8eb2fe5.jpg)
[EDA] chip layout design: VLSI layout design using electric

八大误区,逐个击破(2):性能差?应用程序少?你对云的这些担心很多余!

Freshman girls' nonsense programming is popular! Those who understand programming are tied with Q after reading
随机推荐
Array -- fancy traversal technique of two-dimensional array
Binary tree (thoughts)
机器人雅可比求解
itkMultiResolutionImageRegistrationMethod
Getting to know blob objects
Promise+ handwritten promise
嵌入式系統硬件構成-基於ARM的嵌入式開發板介紹
Binary tree (serialization)
分享PDF高清版,系列篇
Known as the next generation monitoring system! See how awesome it is
Soft test network engineer notes
数组——二维数组的花式遍历技巧
Numpy numerical calculation basis
itk 多分辨率图像 itk::RecursiveMultiResolutionPyramidImageFilter
MUI登录数据库完善与AJAX异步处理【MUI+Flask+MongoDB+HBuilderX】
Eight misunderstandings are broken one by one (2): poor performance? Fewer applications? You worry a lot about the cloud!
[an Xun cup 2019]iamthinking
[HXBCTF 2021]easywill
Openmax (OMX) framework
itkMultiResolutionImageRegistrationMethod