I am trying to figure out the shortest, most pythonic way to implement a similar to the following syntax:
if A and (B if C):
print(A)
in a way that:
- if C is False, then
Bis omitted (therefore(B if C)is True). - if C is True, then B is evaluated, effectively making the syntax
if A and B:
This can be made through various separate if statements, but my ultimate purpose with this was to make it into a list comprehension for a value assignment.
Edit:
The list comprehension I wanted to make was this:
methods = [name for (name, func) in locals().items() \
if callable(func) and (not __name__ == '__main__' or \
func.__module__ == __name__)]
So that it returns the function names I have defined in that module as well as if methods is imported from the outside.
if A and (B if C else True):or(A and B) if C else A:A, B = True and C = False -> TrueandA,B,C = True -> Trueright? If so then it would beif A and not C or B: