Question:
There is a list with two elements (there are always two of them):
any_list = [5, 7]
And meaning:
item = 5
How can I nicely/correctly get the opposite value from the list?
At the moment, only the helper function comes to mind
def get_another_item(any_list, item):
for i in any_list:
if item != i:
return i
Answer:
You can use the result of a boolean expression ( 0
/ 1
) as an index.
Example:
any_list = [5, 7]
item = 5
r = any_list[any_list[0] == item] # 7