python坎坷路

本文探讨了Python编程中的一些常见问题,包括嵌套list的深拷贝与浅拷贝的区别,字典在不同Python版本中的有序性和无序性,以及Python 3.5版本遇到的`undefined symbol: _PyThreadState_UncheckedGet`链接错误及其解决方案。了解这些知识点有助于提高Python编程的效率和避免潜在问题。

1, 嵌套list的深拷贝浅拷贝

list1=list2[:]
list1=list2.copy()
'''
这里的深拷贝是指列表第一层的深拷贝!!!
针对嵌套列表为了深拷贝,采用如下方式:
'''
import copy
list1=copy.deepcopy(list2)

2,字典的有序和无序

Python3.5 之前的字典是无序的!!!
为了兼容版通过以下方式

from collections import OrderedDict
dict=OrderedDict()

为什么Python 3.6以后字典有序并且效率更高?
pyhon3.5的字典底层实现原理

my_dict['name'] = 'kingname'
#内存示意图
[[---, ---, ---],
[---, ---, ---],
[---, ---, ---],
[---, ---, ---],
[---, ---, ---],
[1278649844881305901, 指向name的指针, 指向kingname的指针],
[---, ---, ---],
[---, ---, ---]]

pyhon3.6之后的字典底层实现原理

此时的内存示意图
indices = [1, 0, None, None, None, None, 2, None]

entries = [[-5954193068542476671, 指向name的指针, 执行kingname的指针],
          [9043074951938101872, 指向address的指针,指向xxx的指针],
          [7324055671294268046, 指向salary的指针, 指向999999的指针]
         ]

此时的插入顺序有所保留,不会再因为hash值求余后随机变化.
注: 坑位有人,则采用开放寻址法,如果坑满,则扩容.
开放寻址法

hash算法散列:

A hash function is any function that can be used to map data of arbitrary size to data of fixed size. The values returned by a hash function are called hash values, hash codes, digests, or simply hashes. One use is a data structure called a hash table, widely used in computer software for rapid data lookup. Hash functions accelerate table or database lookup by detecting duplicated records in a large file. They are also useful in cryptography. A cryptographic hash function allows one to easily verify that some input data maps to a given hash value, but if the input data is unknown, it is deliberately difficult to reconstruct it (or equivalent alternatives) by knowing the stored hash value. This is used for assuring integrity of transmitted data, and is the building block for HMACs, which provide message authentication.
——————————————————————————————————————
Hash functions are related to (and often confused with) checksums, check digits, fingerprints, lossy compression, randomization functions, error-correcting codes, and ciphers. Although these concepts overlap to some extent, each has its own uses and requirements and is designed and optimized differently. The HashKeeper database maintained by the American National Drug Intelligence Center, for instance, is more aptly described as a catalogue of file fingerprints than of hash values.

3, undefined symbol: _PyThreadState_UncheckedGet

主要Python3.5.0,3.5.1版本出现的ABI问题
升级到3.5.4解决

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值