When I try to use indexing to get the last element of my line, it does not work( prints out a blank line). However, when I print the original line it works.
with open( newFile,"w") as f:
f.write("Model Number One" + "\n")
for l in lines:
if "ATOM" in l :
f.write(l[-1]) #Does NOT work, prints empty line
f.write(l) # Prints the whole linem when I only want the last element of the line
lines? Is it a list of strings or a list of lists of strings?linesis a list of strings, then eachlinlinesis a string, and each index is a single character. To split it into a list of whitespace-separated words you wantsplit().