lambda and if

Johann Hibschman johann at physics.berkeley.edu
Mon Jun 12 12:21:21 EDT 2000


matt  writes:

> sure would ... doh! 

Oh, don't do that.  Please?  Just out of respect for anyone who has to
maintain your code.

Functions are easy to define in python, and you don't have to do it
all in one line.  I'd recommend:

def make_name(x):
  suffix = ""
  if x[1] in ("big", "little", "whatever"):
    suffix = x[1]
  name = "%s_%s_%s.txt" % (x[2], x[0], suffix)
  return name
filenames = map(make_name, items)

And, yes, you can just plug this inside any function.

It's longer, but it's both more extensible and easier to read.

-- 
Johann Hibschman                           johann at physics.berkeley.edu



More information about the Python-list mailing list