mardi 27 juillet 2021

How use `if` and `for` in the same line of code? [duplicate]

please look at the following code:

for l in range(len(cosine_scores)):
            for s in range(len(skill_index)):
                if l!=skill_index[s] :
                    if cosine_scores[l][skill_index[s]]>=0.80:
                        print(l)

How I can rewrite this code in the way that if condition satisfy for all s before printing l?

For example if I have

my_list=[[10,8],[8,,0,1,2,7],[6,15,8]]

for i in my_list:
    for j in i:
       if j>5:      # I don't know what I should add here to say if this condition is true for all j in i. 
         print(i)

The correct out put should be [10,8] and [6,15,8].

Aucun commentaire:

Enregistrer un commentaire