0

The code is as follows:

for row in students_list:
    first, middle, last, birth = row["first"], row["middle"], row["last"], row["birth"]
    print(f"{first} {middle + ' ' if middle else ''}{last}, born {birth}")

Output is as follows:

~/pset7/houses/ $ python roster.py Gryffindor
Lavender Brown, born 1979
Lavender Brown, born 1979
Lavender Brown, born 1979
Colin Creevey, born 1981
Colin Creevey, born 1981
Colin Creevey, born 1981
Seamus Finnigan, born 1979
Seamus Finnigan, born 1979
Seamus Finnigan, born 1979
Hermione Jean Granger, born 1979
Hermione Jean Granger, born 1979
Hermione Jean Granger, born 1979
Neville Longbottom, born 1980
Neville Longbottom, born 1980
Neville Longbottom, born 1980
Parvati Patil, born 1979
Parvati Patil, born 1979
Parvati Patil, born 1979
Harry James Potter, born 1980
Harry James Potter, born 1980
Harry James Potter, born 1980
Dean Thomas, born 1980
Dean Thomas, born 1980
Dean Thomas, born 1980
Romilda Vane, born 1981
Romilda Vane, born 1981
Romilda Vane, born 1981
Ginevra Molly Weasley, born 1981
Ginevra Molly Weasley, born 1981
Ginevra Molly Weasley, born 1981
Ronald Bilius Weasley, born 1980
Ronald Bilius Weasley, born 1980
Ronald Bilius Weasley, born 1980

How am I supposed to fix this? I would appreciate even a clue to what is causing the problem. Thanks.

1
  • I think the problem is with your import. Is there a chance you are importing each line thrice? Commented Jul 13, 2020 at 10:37

1 Answer 1

0

Each record is in the database multiple times. Possible causes:

  • import is run multiple times

  • there is a bug in import which inserts multiple rows for each line in the csv.

The data needs to be deleted from the database. That can be done in sqlite3 using the DELETE keyword. Then the cause can be determined.

3
  • Thanks for the help, but it turned out to be some 'intrinsic' bug that printed the numbers that way, and even then check50 considered my output correct somehow. Anyway, thanks for answering :)
    – Bryson Ang
    Commented Jul 13, 2020 at 23:22
  • FWIW check50 would have imported once into an empty database, and thus given the correct output. Unless there's a bug in the unshown code, I stick by my answer. Commented Jul 14, 2020 at 0:33
  • I see what you mean. But thanks for your advice :))
    – Bryson Ang
    Commented Jul 14, 2020 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .