gpt4 book ai didi

python - 有没有更好的方法来写这个?

转载 作者:太空狗 更新时间:2023-10-30 00:12:10 25 4
gpt4 key购买 nike

有更好的方法吗?我觉得自己做错了什么,因为过于重复了。

O = viz.pick(1, viz.WORLD)

BackSetts = ["set_b1b", "set_b2a", "set_b1a", "set_b2b"]
LeftSetts = ["set_l1a", "set_l1b", "set_l2a", "set_l1b"]
NormSetts = ["set_nr_a", "set_nr_b"]
Maps = ["MapA","MapB"]

if O.name in BackSetts:
for i in set(BackSetts)|set(Maps):
WORLD[i].alpha(abs(WORLD[i].getAlpha()-1))

elif O.name in LeftSetts:
for i in set(LeftSetts)|set(Maps):
WORLD[i].alpha(abs(WORLD[i].getAlpha()-1))

elif O.name in NormSetts:
for i in NormSetts:
WORLD[i].alpha(abs(WORLD[i].getAlpha()-1))

最佳答案

简单的转换是:

O = viz.pick(1, viz.WORLD)

BackSetts = ["set_b1b", "set_b2a", "set_b1a", "set_b2b"]
LeftSetts = ["set_l1a", "set_l1b", "set_l2a", "set_l1b"]
NormSetts = ["set_nr_a", "set_nr_b"]
Maps = ["MapA","MapB"]
anyset = []

if O.name in BackSetts:
anyset = set(BackSetts)|set(Maps)

elif O.name in LeftSetts:
anyset = set(LeftSetts)|set(Maps)

elif O.name in NormSetts:
anyset = NormSetts

for i in anyset:
WORLD[i].alpha(abs(WORLD[i].getAlpha()-1))

这需要注意 NormSetts 不会像您的原始代码中那样与 Maps 联合。

关于python - 有没有更好的方法来写这个?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4047679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com