Python中数组的几种使用方法
2017-09-04 15:57
686 查看
二维数组的初始化
matirx_done = [[0 for i in range(0, len(matirx))]for j in range(0, len(matirx[0]))]
就将其初始化为一个与
matrix相同大小的元素全为 0 的矩阵
数组的多级排序
在数组idea_collect = [[3, 1, 2], [3, 2, 1], [3, 2, 2], [3, 1, 1]]中, 先按照第二项排列, 再按照第三项倒序排列 可写为:
idea_collect.sort(key=lambda x: (x[1], -x[2]))
其中,
x[1]代表第二项正序排列,
-x[2]代表第三项倒序排列
排列结果为
[[3, 1, 2], [3, 1, 1], [3, 2, 2], [3, 2, 1]]
在一个 class 中多个函数不传参使用同一个数组
如例所示:class Partition: def __init__(self): self.num_complete = [] def partition(self, num, start, end): self.num_compelete = num def partition_core(self): del self.num_compelete[0]
其中,
self.num_compelete就是 class 中两个函数同时可以直接调用的数组, 不过最好先在
def __init__中声明这个数组
相关文章推荐
- 对Python中数组的几种使用方法总结
- 几种快速将数组转换为List的方法,使用Arrays,Collections这两个工具类。
- Python之数组(array)使用方法总结与Numpy中的数组用法
- python使用append合并两个数组的方法
- 使用Python3 打印九九乘法表的几种方法
- Python3爬虫之五网页下载器的几种方法【Python使用cookie模拟登录CSDN】
- Ruby Python Java C C++ 数组使用方法对比
- Python之数组(array)使用方法总结与Numpy中的数组用法
- 使用python获取本地时区的几种方法
- 对python numpy数组中冒号的使用方法详解
- Python之数组(array)使用方法总结与Numpy中的数组用法
- 关于javascript里面仿python切片操作数组的使用方法
- 【python】numpy数组(array)扩充(复制)方法repeat和tile的使用
- python 列表去重(数组)的几种方法
- python unittest.TestLoader()类的几种寻找testcase的方法的使用
- js中使用splice删除数组中某一项或几项的几种方法
- python 列表去重(数组)的几种方法
- NSArray使用方法,数组遍历的几种方法,迭代器的用法
- 将Java应用程序本地编译为EXE的几种方法(推荐使用JOVE和JET)
- java中使用代理访问网络的几种方法