<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def avg_time(self, source=None):
 """ Returns the average time taken to scrape lyrics. If a string or a function is passed as source, return the average time taken to scrape lyrics from that source, otherwise return the total average. """

        if source is None:
            runtimes = []
            for rec in self.source_stats.values():
                runtimes.extend([r for r in rec.runtimes if r != 0])
            return avg(runtimes)
        else:
            if callable(source):
                return avg(self.source_stats[source.__name__].runtimes)
            else:
                return avg(self.source_stats[source].runtimes)