[1106,1107,1127,1207,1212,1213,1301,1302,1402,1405,1406,1505,1506,1510,1601,1603,1605,1728,1729,1730] 1106的11代表一年1班的号码,1213的12代表一年2班的号码,1301代表一年3班的号码以此类推,要求重新排列列表,每次选取一个班的号码比如1106,1207,1301,1402,1505...重新排列整合列表
# 原始列表
data = [1106, 1107, 1127, 1207, 1212, 1213, 1301, 1302, 1402, 1405, 1406,
1505, 1506, 1510, 1601, 1603, 1605, 1728, 1729, 1730]
# 用于存储分组数据
grouped = {}
# 分组,按班级号码分组
for number in data:
year = str(number)[:2] # 前两位为年份
class_number = str(number)[2:] # 后两位为班级编号
if year not in grouped:
grouped[year] = []
grouped[year].append(number)
# 重新排列
max_classes = max(len(v) for v in grouped.values()) # 找到最大班级数
new_order = []
# 逐个班级提取号码
for class_index in range(max_classes):
for year in sorted(grouped.keys()): # 按年级排序
if class_index < len(grouped[year]): # 确保班级存在
new_order.append(grouped[year][class_index])
# 输出结果
print(new_order)
本文转载自互联网,如有侵权,联系删除。