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.
functional or anything in particular. However if you spot something
to improve then I am happy to learn.
def output_random_l esson_of_type(s elf, type=None):
"""Output a lesson of a specific type.
If no type is passed in then output any type."""
output_lessons = self.lesson_dat a["lessons"]
if type:
filtered_lesson s = filter(lambda x: x["type"] == type,
self.lesson_dat a["lessons"])
if filtered_lesson s:
output_lessons = filtered_lesson s
else:
print "Unable to find lessons of type %s." % type
return self.output_ran dom(output_less ons)
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_ran dom to a single instance in the return statement
Cheers,
James
Comment