File size: 660 Bytes
c35855b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re
from collections import Counter

def parse_timetable(text):
    raw_list = []
    subject_counts = Counter()
    
    # Optimized pattern to handle both "DBMS /A /KKD" and "DS /NR" scenarios.
    # Group 1: Subject, Group 2: Division (optional), Group 3: Faculty
    pattern = r"([A-Z]{2,})\s*/\s*(?:([A-Z]?)\s*/\s*)?([A-Z0-9]{2,})"
    matches = re.finditer(pattern, text)
    
    for match in matches:
        subject = match.group(1).strip()
        faculty = match.group(3).strip()
        
        raw_list.append({"subject": subject, "faculty": faculty})
        subject_counts[subject] += 1
        
    return raw_list, dict(subject_counts)