Python:选择其他值

Oli*_*Oli 4 python list

请原谅(或改进标题),但我有一个愚蠢的小问题让我非常不确定.

我有一个列表,可以包含一到两个值,从不更多,从不更少,只有这两个选项:

options = ['option one', 'option two']
Run Code Online (Sandbox Code Playgroud)

正如我所说,有时列表中可能只有其中一个值,所以它可能就是这样 ['option two',]

其范围是在网站上进行简单导航.我接受查询字符串入口并在列表中搜索这些选项:

current_option = request.GET.get('option', options[0])
if not current_option in options: current_option = options[0]
Run Code Online (Sandbox Code Playgroud)

如果未提供"选项",则默认为第一个可用选项.

但现在我想知道一种选择是什么.如果"option one"是输入,我想要"option two".例如,如果仅"option one"options列表中,我希望返回False.

我知道我可以遍历列表,但感觉应该有更好的方法来选择其他值.

Sve*_*ach 10

options.remove(current_option)
options.append(False)
return options[0]
Run Code Online (Sandbox Code Playgroud)

编辑:如果您不想修改options,您也可以使用稍差的可读性

return (options + [False])[current_option == options[0]]
Run Code Online (Sandbox Code Playgroud)