Python: Appending a list doesn't actually append it?
Question: I have a CSV file with names and scores in it. I've made each line a separate
list but when appending a variable to this list it doesn't actually do it. My
code is:

    
    
    import csv
    f = open('1scores.csv')
    csv_f = csv.reader(f)
    newlist = []
    for row in csv_f:
        newlist.append(row[0:4])
    
        minimum = min(row[1:4])
        newlist.append(minimum)
    print(newlist)
    

With the data in the file being

    
    
    Person One,4,7,4
    Person Two,1,4,2
    Person Three,3,4,1
    Person Four,2
    

Surely the output would be `['Person One', '4', '7', '4', '4']` as the minimum
is 4, which I'm appending to the list. But I get this: `['Person One', '4',
'7', '4'], '4',` What am I doing wrong? I want the minimum to be inside the
list, instead of outside but don't understand.


Answer: Append the min to each row and then append the row itself, you are appending
the list you slice first then adding the min value to newlist not to the
sliced list:

    
    
    for row in csv_f:
        row.append(min(row[1:],key=int)
        newlist.append(row)
    

You could also use a list comp:

    
    
    new_list =  [row + [min(row[1:], key=int)] for row in csv_f]
    

You also need the, `key=int` or you might find you get strange results as your
scores/strings will be compared lexicographically:

    
    
    In [1]: l = ["100" , "2"] 
    
    In [2]: min(l)
    Out[2]: '100'
    
    In [3]: min(l,key=int)
    Out[3]: '2'
    

