I am trying to take a list of few numbers and split every number to a new line into new file.
Thus
f=['Hans', 'Anna', 'Vladimir', 'Michael', 'Ed', 'Susan', 'Janice', 'Jo'] in a file names.txt need to take len of the list in f and separate each len to new line.
['4 4 8 7 2 5 6 2 '] should be in a created file
4
8
7
2
5
6
2
Tthis is what I did :
with open("names.txt","r") as f:
f=f.read()
f=f.split() # take from original file
def size(x):
with open("name_length.txt","w") as w:
l=[str(len(n))+' ' for n in x] # create the len list
l="".join(l)
l=str(l)
l=l.split('\n+')
print(f'this,{l}')
print(f'this is,{l}')
w.writelines(l)
return l
print(size(f))