jeudi 1 mars 2018

Python: How to test conditions for an item in a list which calls a function for each item that returns True or False? [on hold]

For example my code looks like this :

for item in mylist:

    while (function(item)==True): #my function returns boolean True or False

        if (((list(str(item)))[:2]) == ['4','1']:
            j+=1

        if (((list(str(item)))[0]) == '1'):
            k+=1

But I get this error message: if (((list(str(item)))[0]) == '1'): IndexError: list index out of range

Aucun commentaire:

Enregistrer un commentaire