当前位置:网站首页>Container summary
Container summary
2022-07-27 19:56:00 【Hug Mo Mo】
Containers :python Several official containers
list: list
set: aggregate
tuple: Tuples
dict: Dictionaries
One , list :
ls = []
ls = list()
Access elements through subscripts
Common ways to list :
append( Elements )# Append an element to the end of the list
insert( Index position , Elements )# In a specific place , Additive elements
clear() # Clear the list
count(element)# Count the number of occurrences of elements
index(element)# The index of the query element appears for the first time , If it doesn't exist , Throw an exception
remove(element) # Remove the corresponding element through the element
pop([index])# Delete the last element by default , If a location is specified , Then delete the element at the corresponding position
reverse() # Flip list order
copy() # Shallow copy objects ( Replication of heap objects )
extend( Iteratable object ) # Merge list
sort()# Sort
Multidimensional list :
[[],[],[],[],[]]
Two ,Set( aggregate ):
1、 Definition set aggregate
s = { Elements 1, Elements 2...}
s = set()
s = set({ Elements 1, Elements 2...})
s = set([ Elements 1, Elements 2...]) # take list Convert to set object
ls = list({ Elements 1, Elements 2...}) # take set Convert to list object
2, Common methods
add( Elements ) # add to
clear
copy
remove # Remove... By the element itself , If the element does not exist , Throw an exception
discard # Remove... By the element itself , If the element does not exist , Then do nothing
pop() # Remove elements at random
intersection# intersection
union # Combine
difference# Difference set
update # Merge sets
3、 ... and , Tuples (tuple):
Tuples are immutable data types .
Elements in tuples are not allowed to be modified or changed .
Definition of tuple :
t = ()# Define tuples , But it's not recommended to use , Because tuples are immutable
t = (" In the spring ", " In the summer ", " autumn ", " In the winter ") # It is recommended to initialize the value when defining
(2), Common methods :
count# Number of statistical elements
index# Query the index of the element
Four , Dictionaries (dict):
dictionary, It's a use key-value The structure of key value pairs stores data
python in key Can't repeat , Otherwise, the data will be overwritten
key The type of can only be string ,value Any type
How to access dictionary values :
Use... In the dictionary key obtain key Corresponding value
d["name"]# obtain name Corresponding value , If it's time to key non-existent , Throw an exception
d.get("age")# You can also use get Method , If key non-existent , Then return to None
Common ways of Dictionary
clear
copy
fromkeys()# Convert other iteratable objects to dictionaries
get
items() # Iterate out each key value pair [(),()]
keys() #
value()
setdefault() # newly added key and value
update
popitem # Pairs are returned in LIFO (last-in, first-out) order
pop(key) # adopt key, Delete key Corresponding key value pair
边栏推荐
- [basic knowledge of deep learning - 42] detailed explanation of logistic regression
- SystemService(系统服务)
- 程序设计综合实验三
- [basic knowledge of in-depth learning - 40] Why does CNN have more advantages than DNN in the field of images
- C243:考试排名
- The first in the field of mobile phone chip design in the world! Ziguang zhanrui won the international certification of tmmi4
- 被动收入:回归原始且安全的两种赚取方法
- Count the six weapons of the domestic interface cooperation platform!
- 【深度学习基础知识 - 37】解决正负样本不均衡 Focal Loss
- 强化学习介绍
猜你喜欢

成年人只有一份主业是要付出代价的,被人事劝退后,我哭了一整晚

注入攻击

统一建模语言 (UML) 规范

Map and set

FileOutputStream(文件储存)与FileInputStream(文件读取)

四大组件之ContentProvider

中国业务型CDP白皮书 | 爱分析报告
![[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula](/img/9f/b9d7503404e068495fd8613df29366.png)
[basic knowledge of deep learning - 46] Bayesian theorem and conditional probability formula

Intent (whether there is return value to jump)

DatePicker(日期选择器)与TimePicker(时间选择器)
随机推荐
函数总结
SharePreference(存储)
[basic knowledge of deep learning - 49] kmeans
Online Judge 输出超限
黑客入门教程(非常详细)从零基础入门到精通,看完这一篇就够了。
File operation protection
transformers-bert
[basic knowledge of in-depth learning - 40] Why does CNN have more advantages than DNN in the field of images
Marqueetextview (running lantern)
Togglebutton (button switch)
使用VS编译NCNN
内置模块10.18
Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
Oppo released the first AR glasses and announced that it would invest 50billion in research and development in the next three years
GestureDetector(手势识别)
ContextMenu (context menu)
What's new in helix QAC 2022.2, the ace code static testing tool (2)
[deep learning target detection series - 01] what is target detection
注入攻击
Use of jvisualvm