Sometimes, while working with Python lists, we can have a problem in which we need to find if all the values that are valid (Non None). This has a lot of application in day-day programming. Let’s discuss a method in which this task can be performed.
Method : Using iterator +
all() + any()
Combination of above functions can be used to perform this particular task. In this, we filter the leading None values using initial all(), then check for singular valid value sublist using any() and then check for all the required None values. If any of the above return false. The Non-None values are not contiguous.
The original list : [None, None, 'Gfg', 'is', 'Good', None, None, None] Are non-none values contiguous ? : True
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.