Nov-23-2019, 05:35 AM
i would like to know if these six code samples would be different enough to consider which would be the best performer and if this would be a pythonic consideration. if so, which is most pythonic? the condN function calls are just sample place holders for various condition expressions in each. there will typically be more than three conditions (probably at least six but i didn't want to make this post that big).
#1
#1
# cond1, cond2, and cond3 are mutually exclusive. # no more than one can be true for the same value. def my_function(a): if cond1(a): return yyy1(xxx1(a)) if cond2(a): return yyy2(xxx2(a)) if cond3(a): return yyy3(xxx3(a)) return None#2
# cond1, cond2, and cond3 are mutually exclusive. # no more than one can be true for the same value. def my_function(a): if cond1(a): return yyy1(xxx1(a)) elif cond2(a): return yyy2(xxx2(a)) elif cond3(a): return yyy3(xxx3(a)) return None#3
# cond1, cond2, and cond3 are mutually exclusive. # no more than one can be true for the same value. def my_function(a): if cond1(a): foo = yyy1(xxx1(a)) if cond2(a): foo = yyy2(xxx2(a)) if cond3(a): foo = yyy3(xxx3(a)) else: foo = None return foo#4
# cond1, cond2, and cond3 are mutually exclusive. # no more than one can be true for the same value. def my_function(a): if cond1(a): foo = yyy1(xxx1(a)) elif cond2(a): foo = yyy2(xxx2(a)) elif cond3(a): foo = yyy3(xxx3(a)) else: foo = None return foo#5
# cond1, cond2, and cond3 are mutually exclusive. # no more than one can be true for the same value. def my_function(a): foo = None if cond1(a): foo = yyy1(xxx1(a)) if cond2(a): foo = yyy2(xxx2(a)) if cond3(a): foo = yyy3(xxx3(a)) return foo#6
# cond1, cond2, and cond3 are mutually exclusive. # no more than one can be true for the same value. def my_function(a): foo = None if cond1(a): foo = yyy1(xxx1(a)) elif cond2(a): foo = yyy2(xxx2(a)) elif cond3(a): foo = yyy3(xxx3(a)) return foo
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.