0

The code below just makes it have one letter/number per line then it forms a new line, but I would like to have the numbers on each line and only form a new line everywhere there is a comma.
Is there a way to do this?
Thanks!

def hyp(aFile, bFile):
    lista = []
    a = open(aFile, "r")    
    b = open(bFile, "w")
    line = a.readline()

    for line in a:
        words = line.split()
        lista.append(words)
        value = str(lista)


    trunk = map(lambda x: math.sqrt(float(x[0])**2 + float(x[1])**2), lista)
    trunk1 = str(trunk)

    for answer in trunk1:
        b.write("%s\n"%answer)
    
    
    a.close()
    b.close()

Edited by Zealhack: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Zealhack
0

"\n" is the newline character, so you are appending a newline every time you write "answer", so remove it there and add a statement to b.write "\n" every time a comma is found (and it is not apparent from the code posted how you test for a comma). Note that you can use either "readline()" or "for line in a:" but not both.

Edited by woooee: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.