Skip to content

Instantly share code, notes, and snippets.

@rahulbanerjee26
Created September 25, 2022 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulbanerjee26/4ace813b3677627566df0d14eeae4680 to your computer and use it in GitHub Desktop.
Save rahulbanerjee26/4ace813b3677627566df0d14eeae4680 to your computer and use it in GitHub Desktop.
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