<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _create_user_profiles(self, profiles, file, valid_records, ip_user=False, year=None, week=None):
 """ Create user profiles with all the records visited or downloaded. Returns: Dictionary with the user id and a record list. {'2323': [1, 2, 4]} """

        for record in file.get_records():
            recid = record[2]
            if not valid_records.get(recid, None):
                # Record not valid
                continue

            if ip_user:
                ip = record[4]
                user_agent = record[5]
                # Generate unique user id
                user_id = "{0}-{1}_{2}_{3}".format(year, week, ip, user_agent)
                try:
                    uid = hashlib.md5(user_id.encode('utf-8')).hexdigest()
                except UnicodeDecodeError:
                    logger.info("UnicodeDecodeError {}".format(user_id))
            else:
                uid = record[1]

            profiles[uid].append(recid)

        return profiles