假设我有这个列表:
a = [('student', '100'), ('student', '101'),
('student', '102'), ('student', '103'),
('student', '104'), ('student', '105'),
('student', '106'), ('student', '120'),
('student', '121'), ('student', '122'),
('student', '123'), ('student', '124'),
('teacher', '21'), ( 'teacher', '22'),
('teacher', '23'), ('teacher', '24'),
('teacher', '25'), ('teacher', '26'),
('teacher', '27'), ('teacher', '51'),
('teacher', '52'), ('teacher', '53'),
('teacher', '60'), ('Zstudent', '55'),
('Zstudent', '56'), ('Zstudent', '57'),
('Mstudent', '30'), ('Mstudent', '31')]
我怎样才能输出:
student 100-106 120-124
teacher 22-27 51-53 60
Zstudent 55-57
Mstudent 30-31