📜  将列表分成两半 python 代码示例

📅  最后修改于: 2022-03-11 14:46:56.100000             🧑  作者: Mango

代码示例1
print(a_list)
length = len(a_list)
middle_index = length//2
first_half = a_list[:middle_index]
second_half = a_list[middle_index:]
print(first_half)
print(second_half)

>> [1, 2, 3, 4]
>> [1, 2]
>> [3, 4]