3

i am new to python and i need to read numbers from a text file and pass those in order into a list here is what i came up with :

liste = []
with open("MDATX3.014") as fa:
    lines = fa.readlines()
    for line in lines:
        words = line.split()
        for word in words:
            liste.append(word)
            print(liste)

and i had the result like this enter image description here

1
  • So what is the problem? Commented Aug 23, 2018 at 1:48

1 Answer 1

2

You should print(liste) outside the loop if you don't want to see its intermediate values while it is being appended with new values:

liste = []
with open("MDATX3.014") as fa:
    lines = fa.readlines()
    for line in lines:
        words = line.split()
        for word in words:
            liste.append(word)
print(liste)
Sign up to request clarification or add additional context in comments.

1 Comment

i will in 3 mins)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.