I am doing some validation of the input data of one program I have created. I am doing this with assert. If assertion arises I want to know in which part of the data occurs so I want to get the value that arises the assertion.
assert all(isinstance(e, int)
for l1 in sequence.values()
for l2 in l1 for e in l2),"Values of the dictionnary aren't lists of integers. Assert found in '{l2}'"
# This code doesn't work
Not when using all
as it does not expose the "iteration variable". You will need an explicit, nested loop. You also forgot the f''
prefix to denote an f-string:
for l1 in [['a']]:
for l2 in l1:
for e in l2:
assert isinstance(e, int), f"Values of the dictionnary
aren't lists of integers. Assert found in '{l2}'"
AssertionError: Values of the dictionnary aren't lists of integers. Assert found in 'a'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With