Amazon Online Assessment (OA) 2021 - Reorder Data in Log Files | Upgrading Junction Boxes | HackerRank

Practice on leetcode here: https://leetcode.com/problems/reorder-data-in-log-files/

Solution

1from typing import List
2
3def reorder_log_files(logs: List[str]) -> List[str]:
4    alphas = []
5    nums = []
6    for log in logs:
7        ident, cont = log.split(' ', 1)
8        (alphas if cont[0].isalpha() else nums).append((cont, ident))
9    alphas.sort()
10    return [f'{i} {c}' for c, i in alphas + nums]
11
12if __name__ == '__main__':
13    logs = [input() for _ in range(int(input()))]
14    res = reorder_log_files(logs)
15    for line in res:
16        print(line)
17

Still not clear?Β SubmitΒ the part you don't understand to our editors.