you are almost there
Instead of this
for x in range(3):
f = open('g[x].txt','w')
Do this:
for x in range(3):
f = open(g[x]+'.txt','w')
The actual problem is 'g[x].txt' it is a string and it's value does not change during each iteration where as to get g elements we use g[x] which return a string which then can be appended with '.txt' to form the file name
You could use context manager to open the file object
i.e)
for x in range(3):
with open(g[x]+'.txt','w') as f:
If you want both index and value then you could use enumerator
i.e.)
for index,value in enumerate(g):
with open(value+'.txt','w') as f: