Help with python list-comprehension

Posted by leChuck on Stack Overflow See other posts from Stack Overflow or by leChuck
Published on 2010-04-09T12:50:40Z Indexed on 2010/04/09 12:53 UTC
Read the original article Hit count: 219

Filed under:
|
|

A simplified version of my problem:

I have a list comprehension that i use to set bitflags on a two dimensional list so:

s = FLAG1 | FLAG2 | FLAG3
[[c.set_state(s) for c in row] for row in self.__map]

All set_state does is:

self.state |= f

This works fine but I have to have this function "set_state" in every cell in __map. Every cell in __map has a .state so what I'm trying to do is something like:

[[c.state |= s for c in row] for row in self.map]

or

map(lambda c: c.state |= s, [c for c in row for row in self.__map])

Except that neither works (Syntax error). Perhaps I'm barking up the wrong tree with map/lamda but I would like to get rid on set_state. And perhaps know why assignment does not work in the list-comprehension

© Stack Overflow or respective owner

Related posts about python

Related posts about list-comprehension