Request a short code review

james at reggieband.com james at reggieband.com
Thu Apr 17 18:11:40 EDT 2008


> I am not necessarily looking to make the code shorter or more
> functional or anything in particular.  However if you spot something
> to improve then I am happy to learn.

To give an example of what I mean I have already altered the code:

def output_random_lesson_of_type(self, type=None):
    """Output a lesson of a specific type.
       If no type is passed in then output any type."""
    output_lessons = self.lesson_data["lessons"]
    if type:
        filtered_lessons = filter(lambda x: x["type"] == type,
            self.lesson_data["lessons"])
        if filtered_lessons:
            output_lessons = filtered_lessons
        else:
            print "Unable to find lessons of type %s." % type
    return self.output_random(output_lessons)

Changes:
 - Respected a column width of 80
 - Created the output_lessons variable, assigned it to a default.
   This remove an else statement and reduced the call to
   self.output_random to a single instance in the return statement

Cheers,
James



More information about the Python-list mailing list