Reorder Data in Log Files

Problem Id: 937 Difficulty: Easy


Intuition

Solution


class Solution:
    def reorderLogFiles(self, logs: List[str]) -> List[str]:
        letter_logs = []
        digital_logs = []
        for line in logs:
            if line.split(' ')[1][0] in string.digits:
                digital_logs.append(line)
            else:
                letter_logs.append(line)
        letter_logs.sort(key=lambda s: s.split(' ')[1:] + [s.split(' ')[0]])
        return letter_logs + digital_logs