另一个列表理解问题
我有这样的:
if Setting["Language"] == "en":
f.m_radioBox3.SetSelection(0)
elif Setting["Language"] == "pt":
f.m_radioBox3.SetSelection(1)
elif Setting["Language"] == "fr":
f.m_radioBox3.SetSelection(2)
elif Setting["Language"] == "es":
f.m_radioBox3.SetSelection(3)
然后我这样做了:
Linguas = ["en","pt","fr","es"]
a = 0
for i in Linguas:
if i == Setting["Language"]:
f.m_radioBox3.SetSelection(a)
a += 1
是否有可能进一步简化它并将其变成一行行?
I had this:
if Setting["Language"] == "en":
f.m_radioBox3.SetSelection(0)
elif Setting["Language"] == "pt":
f.m_radioBox3.SetSelection(1)
elif Setting["Language"] == "fr":
f.m_radioBox3.SetSelection(2)
elif Setting["Language"] == "es":
f.m_radioBox3.SetSelection(3)
Then I did this:
Linguas = ["en","pt","fr","es"]
a = 0
for i in Linguas:
if i == Setting["Language"]:
f.m_radioBox3.SetSelection(a)
a += 1
Is it possible to further simplify this and make it into a one-liner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者你可以用字典来做到这一点:
or you could do it with a dictionary:
如果您不需要检查设置是否是可接受的值之一,则它将变为:
If you don't need to check for the setting being one of an acceptable number of values, it becomes: