I'm trying to make a bit more readable logging messages for my program.
For this purpose I'm searching a way to implement sort of advanced 'any' iterator.
It should either way return index of satisfying data index or iterated cell itself instead of just returning True/False on satisfied condition.
Here is a possible pseudo-code for explanation:
messages = [(0, None),(1, None), (2, "data")]
if any(data is not None for id, data in messages):
print(f"Tuple with data has id: {id} and data: '{data}'.")
else:
print(f"There is no message with filled data")
# should output: "Tuple with data has id: 2 and data: 'data'."
I've tried several ways like using walrus operator, using global operator, print inside if operator or even implementing my own iterator
(but this topic is new for me so probably it still can be a solution)
I would like to avoid any extra for cycle for better optimization, readability and also for mastering python.
Thank you for any ideas in advance!