Friday, 30 August 2013

Python - map() and list of objects

Python - map() and list of objects

There is a list of objects in the variable games.
for g in games:
if g.clam ==5: g.new_var=1
if g.clam ==4: g.new_var=0
How do I get the above functionality using the map() function? I tried
something like the following, but I think it is not close to the right
way.
def assign_var(clam):
if clam==5: return 1
if clam==4: return 0
games.new_var = map(assign_var, games.clam)

No comments:

Post a Comment