Q:

Subtracting from a single element in a list?

I am quite new to Python learning how it works this is a program I've made and I cant seem to reduce the quantity
How do you subtract a specific number from a single element in a list?
    import csv
    stockfile = open("Stock list.txt")
    csvf = csv.reader(stockfile,delimiter = ",")
    #Sets csvf vaiable to open text file
    #Delimiter is what seperates your values

    code = []
    item = []
    price = []
    quantity = []
    quantity = list(map(int, quantity))

    for row in csvf:
    code.append(row[0])
    item.append(row[1])
    price.append(row[2])
    quantity.append(row[3])

    usersearch = input("Please enter a 7-digit code: ")
    #Asks the user to enter the unique item codes
    while usersearch not in code:   
    print("This is not a valid 7-digit code")
    usersearch = input("Please enter a 7-digit code: ")
        if usersearch in code:               
        print("The code has been found")
        index = code.index(usersearch)  
        print("The item you have chosen is: %s"%item[index])   
        print("The price is: £%s"%price[index])                 
        print("There are %s left in stock"%quantity[index])
        quantity[index] -= 1

I want to reduce the quantity[index] by 1
When I use quantity[index] -= 1 I get an error:
TypeError: unsupported operand type(s) for -=: 'str' and 'int'
These are the contents of the file:  
0000001,PS4,300,50
0000011,Xbox One,300,50
0000111,Need for Speed,40,20
0001111,Just Cause 3,45,24
0011111,Dualshock 4,48,30
Never mind I figured it out, the quantity=list(map(int, quantity)) had to come just before the quantity[index] -= 1

A:

You could use augmented assignment, -=:
a[4] -= 3

Or just re-assign the result of a subtraction back to the index (which is what -= does anyway):
a[4] = a[4] - 3

