An Interest In:
Web News this Week
- April 2, 2024
- April 1, 2024
- March 31, 2024
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
November 6, 2022 09:09 am GMT
Original Link: https://dev.to/salahelhossiny/reorder-data-in-log-files-17k8
Reorder Data in Log Files
You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier.
There are two types of logs:
Letter-logs: All words (except the identifier) consist of lowercase English letters.
Digit-logs: All words (except the identifier) consist of digits.
Reorder these logs so that:
The letter-logs come before all digit-logs.
The letter-logs are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.
The digit-logs maintain their relative ordering.
Return the final order of the logs.
class Solution: def reorderLogFiles(self, logs: List[str]) -> List[str]: def get_key(log): _id, rest = log.split(" ", maxsplit=1) return (0, rest, _id) if rest[0].isalpha() else (1, ) return sorted(logs, key=get_key)
Original Link: https://dev.to/salahelhossiny/reorder-data-in-log-files-17k8
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To