How do I remove string ” from python dictionary list values?

The loadInventory function with a string filename as parameter reads the contents from inventory.txt

def loadInventory(filename):
    inventory = {}
    inventoryFile = open(filename)
    for line in inventoryFile:
        itemID,itemStock = line.split(":")
        inventory[itemID] = itemStock
        inventory = {itemID: itemStock for itemID, itemStock in inventory.items()}
        inventory[itemID] = [itemStock.replace('n', '')]
    
    # print(f"{inventory}")
    return inventory

def main():
    print(loadInventory('Inventory.txt'))
main()

Inventory.txt:

C05:10,10,5,4
C01:0,20,10,5
C11:10,20,10,1
C03:0,0,10,0
C10:1,1,1,1

Output:

{'C05': ['10,10,5,4'], 'C01': ['0,20,10,5'], 'C11': ['10,20,10,1'], 'C03': ['0,0,10,0'], 'C10': ['1,1,1,1']}

Intended Output:

 {'C05':[10,10,5,4], 'C01':[0,20,10,5], 'C11':[10,20,10,1],
      'C03':[0,0,10,0]}

Answer

Try replacing this line:

        inventory[itemID] = [itemStock.replace('n', '')]

To:

        inventory[itemID] = [int(i) for i in itemStock.replace('n', '').split(',')]

Or:

        inventory[itemID] = list(map(int, itemStock.replace('n', '').split(',')]))