I have a list of values... some are valid, some invalid (containing None). I test each element for validity. When I find an invalid element, I need to find indexes of the closest previous and the closest next valid value. I need to treat the list as a cycle, so if there are no valid elements before/after the initial element, it should search from the end/start of the list... This way, if there is at least one valid value in the list, both the previous and the next valid value will be found (it can be the same index, if there is only one valid value in the list).
I am able to solve it, but with a ridiculously complicated code. Could you help me find some elegant solution? I am not a programmer, just using my very humble programming skills to process data in another field.
I am able to solve it, but with a ridiculously complicated code. Could you help me find some elegant solution? I am not a programmer, just using my very humble programming skills to process data in another field.