Python数组合并和数组分割(数组拆分)
数组的合并和拆分
## 将数组按照固定长度进行拆分,返回一个二维数组 def list_split(source_list, n): return [source_list[i:i+n] for i in range(0, len(source_list), n)] if '__main__' == __name__: print("数组拆分(数组分割)") list1 = ['s1', 's2', 's3', 's4', 's5', 's6', 's7','s8'] list2 = list_split(list1, 3) print(list2) ## 遍历二维数组 for newlist in list2: print(newlist) print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~") print("数组合并") list3 = [1,2,3,4,5,6] list4 = ['a','b','c','d','e','f'] ## 使用extend函数进行合并 list3.extend(list4) print(list3)
本文来自博客园,作者:业余砖家,转载请注明原文链接:https://www.cnblogs.com/yeyuzhuanjia/p/17109344.html

浙公网安备 33010602011771号