M
M
Maxim Siomin2020-06-29 12:36:01
Python
Maxim Siomin, 2020-06-29 12:36:01

Why is the data displayed incorrectly?

Here is a test program I wrote:

namesList = []
authorsList = []

with open('Saves/names file.txt', 'r') as namesFile:
    for line in namesFile:
        appendData = line.lower()
        namesList.append(appendData)

with open('Saves/authors file.txt', 'r') as authorsFile:
    for line in authorsFile:
        appendData = line.lower()
        authorsList.append(appendData)

for x in range(0, len(namesList)):
    print(namesList[x],  authorsList[x])

And the output of the program:
book 1
 author 1

book 2 author 2

book 2 author 2 is displayed correctly, but book 1 author 1 is not

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2020-06-29
@MaxSiominDev

Check the resulting lines for the presence of hyphen characters . You
can remove them like this:

with open('Saves/names file.txt', 'r') as namesFile:
    namesList = namesFile.read().splitlines()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question