Answer the question
In order to leave comments, you need to log in
How to write separate values from an array to a json file?
I have 3 files:
Song1.mp3
Song2.mp3
Song3.mp3
And I wrote the following script to get song titles and write them to an array:
import glob, os
massiv = []
for file in glob.glob("*.mp3"):
massiv.append(str(file))
print(massiv)
Answer the question
In order to leave comments, you need to log in
>>> songs_titles = ['Песня1.mp3', 'Песня2.mp3', 'Песня3.mp3']
>>> songs = [{'title': s, 'file': f'https://site.com/{s}'} for s in songs_titles]
>>> songs
[{'title': 'Песня1.mp3', 'file': 'https://site.com/Песня1.mp3'}, {'title': 'Песня2.mp3', 'file': 'https://site.com/Песня2.mp3'}, {'title': 'Песня3.mp3', 'file': 'https://site.com/Песня3.mp3'}]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question