For example I have a list inside a dictionary:
{'results': [{'name': 'sarah', 'age': '18'}]}
I want make a text file and the name of file must be the value of dict 'name'
ex: sarah.txt
.
How should I code it in python?
Something like this:
dictionary = {'results': [{'name': 'sarah', 'age': '18'}]}
name = dictionary['results'][0]['names'] + '.txt'
open(name, "w")
Opening a file in the w
rite mode, if it doesn't exist already, will create a new file with that name.