arrays - python中有可变的二进制数组吗?

标签 arrays python-3.x mutable

Python 3 中是否存在 bool True 或 False 数组的数据结构?此外,这个数组比字节数组的内存效率更高吗?

我需要能够将值从 True 更改为 False 并通过索引访问它;但我不需要能够更改数组的大小。

编辑:此外,如果移动命令比索引更快,这也很好

最佳答案

使用数组怎么样?

import array
a = array.array("B", [0]*10) #fix size of 10 - all False

a[1] = 1 # Mutable, Yay!
print(a)

它将使用最少的内存,并为您提供 O(1) 索引

关于arrays - python中有可变的二进制数组吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36724451/

相关文章:

Python:如何导入 .csv 并通过代码运行内容?

python-3.x - 从具有值列表的列中检索唯一值

arrays - 如何自动将纯代码转换为使用可变数组的代码以提高效率?

c - 使用数组打印出一些星号,这取决于用户在 C 中输入的数字

python-3.x - GCP : Is it possible for a Cloud function to trigger when an Alert fires?

ios - 如何从 NSURLRequest 获取可变数据

java - 安卓位图操作

php - 将空元素插入 PHP 数组

c++ - 为什么我得到 "Invalid Allocation Size: 4294967295 Bytes"而不是 std::bad_alloc 异常?

PHP Array POST UPDATE 只影响最后一行