python - Make function to List-Comprehension -
i have several lines in code similar to
[this.attribute in if something]
is there way create function homecoming in shorter way? because gets tedious creating them , don't find them readable if there's many 'if-conditions'.
edit:
well, spend time trying big list meeting criteria. , need alter criteria , output. so:
[obj obj in object.allobjects if obj.pos == (x,y)] [creature.pos creature in creature.allcreatures if creature not caller] [creature creature in creature.allcreatures if creature.pos == pos , creature not caller]
and on.
maybe i'm doing wrong start.
you outsource conditional function. if it's complex, split complexity , create each part easier read, more or less point of functions in first place.
python function list-comprehension
No comments:
Post a Comment