Python 一维列表 (list) 转换为二维列表 (list)

Python 一维列表 (list) 转换为二维列表 (list)

1. sample 1

#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
Yongqiang Cheng
"""

polylines_list = [1920, 1080, 1280, 720]
interval = 2

polyline_set = []

if (len(polylines_list) % 2 == 0):
    for idx in range(0, len(polylines_list), 2):
        polyline_set.append([polylines_list[idx], polylines_list[idx + 1]])
else:
    print("IndexError: list index out of range.")

print(polyline_set)
[[1920, 1080], [1280, 720]]

你可能感兴趣的:(Python,3.x,-,Python,2.x)