Created
September 25, 2022 22:35
-
-
Save rahulbanerjee26/4ace813b3677627566df0d14eeae4680 to your computer and use it in GitHub Desktop.
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
def getSnippetName(language, snippet): | |
mapLanguagetoFileName = { | |
"python": "__init__.py", | |
"javascript": "index.js", | |
"typescript": "index.ts", | |
} | |
lines = snippet.split("\n") | |
firstLine = lines[0] | |
if "#" in firstLine: | |
return (firstLine.strip("#").strip("\n"), "\n".join(lines[1:])) | |
elif "//" in firstLine: | |
return (firstLine.strip("//").strip("\n"), "\n".join(lines[1:])) | |
else: | |
return (mapLanguagetoFileName.get(language, "newlanguage"), snippet) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment