<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def percent_nocturnal(records, user):
 """ The percentage of interactions the user had at night. By default, nights are 7pm-7am. Nightimes can be set in ``User.night_start`` and ``User.night_end``. """

    if len(records) == 0:
        return 0

    if user.night_start < user.night_end:
        night_filter = lambda d: user.night_end > d.time() > user.night_start
    else:
        night_filter = lambda d: not(user.night_end < d.time() < user.night_start)

    return sum(1 for r in records if night_filter(r.datetime)) / len(records)