def trim_field(self, field):
        """Trim (in-place) the dict provided, keeping the most used items.

        The "locales" and "versions" fields are dicts which have the locale
        or version as the key, and the count as the value.

        """
        def fits(field):
            """Does the json version of the field fits in the db TEXT field?"""
            return (2 ** 16) < len(json.dumps(field))  # Max len of TEXT field.

        if fits(field):
            return
        # Order by count (desc), for a dict like {'<locale>': <count>}.
        values = list(reversed(sorted(field.items(), key=lambda v: v[1])))
        while not fits(field):
            key, count = values.pop()  # Remove the least used (the last).
            del field[key]  # Remove this entry from the dict.
dataset/ETHPy150Open mozilla/addons-server/src/olympia/stats/management/commands/update_counts_from_file.py/Command.trim_field/swapped operands of `<`