jeudi 23 janvier 2020

Python beginners question. Just can't seem to get IF statement working

I am trying to sort a set of data in to 2 separate lists, fulltime and parttime. But it doesn't seem to be working. Can somebody point to where I'm getting this wrong?

data = [(['Andrew'], ['FullTime'], [38]), 
       (['Fred'], ['PartTime'], [24]), 
       (['Chris'], ['FullTime'], [38])]

def sort(var1, datadump):
    positionlist = []
    for b in range(0, len(datadump)):
        temp2 = datadump[b][1]
        if (temp2 == var1):
            positionlist.append(datadump[b])
    return (positionlist)

FullTimeList = sort("FullTime", data) 
PartTimeList = sort("PartTime", data)

print(FullTimeList) 
print(PartTimeList)

Aucun commentaire:

Enregistrer un commentaire