Skip to content

Instantly share code, notes, and snippets.

@BedirYilmaz
Last active March 6, 2024 12:37
Show Gist options
  • Save BedirYilmaz/dc8c6b55a4224c69bda2aa9a78f893ed to your computer and use it in GitHub Desktop.
Save BedirYilmaz/dc8c6b55a4224c69bda2aa9a78f893ed to your computer and use it in GitHub Desktop.
creation of json file whose content are the elements of a list
import json
li = ["Yet each man kills the thing he loves,",
"By each let this be heard,",
"Some do it with a bitter look,",
"Some with a flattering word,",
"The coward does it with a kiss,",
"The brave man with a sword!",
"Some kill their love when they are young,",
"And some when they are old;",
"Some strangle with the hands of Gold:",
"The kindest use a knife, because",
"The dead so soon grow cold.",
"Some love too little, some too long,",
"Some sell and others buy;",
"Some do the deed with many tears,",
"And some without a sigh:",
"For each man kills the thing he loves,",
"Yet each man does not die."]
out_file_path = "path/to/file.json"
with open(out_file_path, "w") as file_out:
json.dump(li, file_out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment