Jan-07-2019, 11:21 AM
(This post was last modified: Jan-07-2019, 11:21 AM by joaomcteixeira.)
Hello,
After using ternary operators extensively I am getting lost in this case. It took me a couple of hours to understand why I was getting bugged, and though I've identified the cause I can't understand why this example works like this.

EDIT: after posting the thread and staring at it, a spark came... ternary operator ended with the comma... so [""] was passed to c even when condition evaluates to True
After using ternary operators extensively I am getting lost in this case. It took me a couple of hours to understand why I was getting bugged, and though I've identified the cause I can't understand why this example works like this.
# pretty clear a = [("1", "2"), ("", "")] b, c = list(zip(*a)) print(b) print(c) ('1', '') ('2', '')
# here I would expect the same as before, however... a = [("1", "2"), ("", "")] b, c = list(zip(*a)) if True else [""], [""] print(b) print(c) [('1', ''), ('2', '')] ['']
# this result is expected but why it differs from the second? a = [("1", "2"), ("", "")] b, c = list(zip(*a)) if True else ([""], [""]) print(b) print(c) ('1', '') ('2', '')Would someone be willing to comment on this?

EDIT: after posting the thread and staring at it, a spark came... ternary operator ended with the comma... so [""] was passed to c even when condition evaluates to True