Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

IndexError: list index out of range positive check in Tuple

Hi I am getting this error to checking the positive value check in the tuple, i am getting this error

my_tuple = []
a=(5,6)
b=(8,9)
#print("The list is :")
my_tuple.append((a,b))
#print(my_tuple)

my_result = [sub for sub in my_tuple[0] if all(element >= 0 for element in sub)]

print(len(my_result))

#print("The result is :")
#print(my_result)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you uncomment all of the commented-out lines, your code runs fine with the following output:

The list is :
[((5, 6), (8, 9))]
2
The result is :
[(5, 6), (8, 9)]

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading