Allie H Allie H - 8 months ago 53
Python Question

python comparing elements in dictionary to a float

If I have a dictionary of pvalues, such that accessing

gives the pvalue from comparing class j to other classes in row i. However, when I try to iterate over the dictionary to find the significant values (i.e., if
pvalues[i][classes[j]] < 0.05
), I get
TypeError: unorderable types: list() < float()
. Is there anyway to compare the list elements to the 0.05 float without flattening the list and losing the class designations? Thanks.


As you mentioned in your comment, Your pvalues[i][classes[j]] is actually giving a list which is then being compare to float. You should compare the first element of that list and the float instead :

if pvalues[i][classes[j]][0] < .5 :
    print("it worked!!!")