Reputation: 173
I have a piece of code that looks like this:
rv.append(get_quest_guide_char("lindsey", **{"marker": ["items cake_slice","items bottle pepelepsi","items apple"] for x in [1] * (game.location == lindsey.location)}))
Baisically, how it works is,
If game.location does not equal lindsey.location, then the result call looks like this, only one argument is passed and that is the lindsey argument.
rv.append(get_quest_guide_char("lindsey"))
If it is true however, then that second argument is added like this
rv.append(get_quest_guide_char("lindsey", marker = ["items cake_slice","items bottle pepelepsi","items apple"]))
How do I insert a third condition to add if the result is true? The code I tried looks like this and it doesn't work.
rv.append(get_quest_guide_char("lindsey", **{"marker_sector": "right_bottom", "marker": ["items cake_slice","items bottle pepelepsi","items apple"] for x in [1] * (game.location == lindsey.location)}))
where the third argument would be marker_sector = "right_bottom"
Upvotes: 1
Views: 46
Reputation: 1132
If I understood what you are trying to do, try this:
rv.append(get_quest_guide_char("lindsey", marker_sector="right_bottom", **{"marker": ["items cake_slice","items bottle pepelepsi","items apple"] for x in [1] * (game.location == lindsey.location)}))
It would add the other kwarg without the condition and simplify the code.
However, I recommend you to refactor this piece of code, maybe defining the argument on a variable outside the append.
if game.location == lindsey.location:
marker = ["items cake_slice", "items bottle pepelepsi", "items apple"]
else:
marker = None
rv.append(get_quest_guide_char("lindsey", marker_sector="right_bottom", marker=marker))
Upvotes: 2