Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way to write this?

Tags:

python

Is there a better way to do this? I feel like I am doing something wrong by being too repetitive.

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))
like image 265
relima Avatar asked Oct 28 '10 22:10

relima


People also ask

How do you reframe a sentence?

One way to rephrase for clarity is to read the sentence once and then set it aside and determine what you're trying to say to your specific audience. Paraphrasing refers to taking what someone else said or wrote and rephrasing it using different words.


1 Answers

The trivial transformation is:

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))

This takes care such that NormSetts is not union'd with Maps, as in your original code.

like image 85
carl Avatar answered Oct 12 '22 22:10

carl