mardi 5 mai 2020

Python List and If Statement issue

I have a list called listExitPrice already created with values in it. I was hoping to separate out this list into multiple other lists as you can see below. I wanted to separate it by looking into the what listExitPrice[k] and checking it it is greater than 0, if it is I wanted to follow the path for else. Vise versa. This code yields "list indices must be integers or slices, not tuples" for the first row of the else statement. Any help would be appreciated! Thanks!

countSell = 0
countHold = 0
for k in listExitPrice:
    if k == 0:
        listBuyDateAP[countHold] = listBuyDate[k]
        listStockNameAP[countHold] = listStockName[k]
        listEntryPriceAP[countHold] = listEntryPrice[k]
        listVolumeAP[countHold] = listVolume[k]
        countHold = countHold + 1
    else:
        listBuyDatePT[countSell] = listBuyDate[k]
        listStockNamePT[countSell] = listStockName[k]
        listEntryPricePT[countSell] = listExitPrice[k]
        listVolumePT[countSell] = listVolume[k]
        listExitPricePT[countSell] = listEntryPrice[k]
        listSellDatePT[countSell] = listSellDate[k]
        countSell = countSell + 1

Aucun commentaire:

Enregistrer un commentaire