私がこのリストを持っているとしましょう:
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