Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
734 B
6
Indexable
Never
from datetime import datetime
from collections import defaultdict

def solution(logs):
    mapping = defaultdict(lambda: defaultdict(lambda : 0))
    
    
    for log in logs:
        if check(log):
            mapping[log[0]][log[2]] += 1
    
    result = []
    for user_id in sorted(mapping):
        for date in sorted(mapping[user_id]):
            result.append([user_id, date, str(mapping[user_id][date])])
    return result

        
        
def check(log):
    try:
        # Combining date and time strings
        datetime_str = f"{log[2]} {log[1]}"
        # Trying to parse the datetime string
        datetime.strptime(datetime_str, "%Y-%m-%d %H:%M:%S")
        return True
    except ValueError:
        return False
Leave a Comment