Created
May 2, 2021 07:58
-
-
Save Park-Developer/521677198d914c6f0ab1c847adc36477 to your computer and use it in GitHub Desktop.
leetcode 937. Reorder Data in Log Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution(object): | |
def reorderLogFiles(self, logs): | |
""" | |
:type logs: List[str] | |
:rtype: List[str] | |
""" | |
digit_log=[] | |
let_temp=[] | |
let=[] | |
for log in logs: | |
temp=log.split(' ') | |
identifier=temp[0] | |
content=' '.join(temp[1:]) | |
if content.replace(' ','').isdigit()==True: | |
digit_log.append(log) | |
else: | |
# DataForm ; [content, identifier , log] | |
let_temp.append([content,identifier,log]) | |
let_temp.sort(key=lambda x:(x[0],x[1])) | |
for log in let_temp: | |
let.append(log[2]) | |
result=let+digit_log | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment