dimanche 18 mars 2018

If else condition for nested list using list index numbers doesn't work

The variable "comma_values" in the below-mentioned if-else statement is a nested list in Python 2.7. The nested list has six daughter lists in each index ranging from 0 to 5. Each daughter list has two floating point numbers separated by a comma. For more insight the example below is an accurate representation of the whole nested list.

Example:- [[5.0,-56],[12,11.7],[3,-5.0],[132,135.0],[44,-12],[32,10]]

The problem encountered is that the if else conditions never work when I try to check for certain conditions in the nested list index locations. Your insights will be appreciated !

PS: I checked that the list by itself does not have any issues when it is passed inside the function as "comma_values". There is something wrong with application of the if else statements for the whole list !

def poly_check(comma_values):
    """Checking if point in region - Right polygon"""
    in_poly = False

    if comma_values[0][0] >= comma_values[0][1] and comma_values[3][0] <= comma_values[3][1] and comma_values[2][0] <= \
        comma_values[2][1] and comma_values[5][0] >= comma_values[5][1]:
        print("In right poly")
        in_poly = True
        break

    """Checking if point in region - Left polygon"""
    elif comma_values[3][0] <= comma_values[3][1] and comma_values[4][0] >= comma_values[4][1] and comma_values[5][0] <= \
        comma_values[5][1]:
        print("In left poly")
        in_poly = True
        break

    else:
        pass
    return in_poly

Aucun commentaire:

Enregistrer un commentaire