<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def chemical_element(self, name_only: bool = True) -> Union[dict, str]: """Generate a random chemical element. :param name_only: If False then will be returned dict. :return: Name of chemical element or dict. :rtype: dict or str :Example: {'Symbol': 'S', 'Name': 'Sulfur', 'Atomic number': '16'} """

        elements = self._data['chemical_element']
        nm, sm, an = self.random.choice(elements).split('|')

        if not name_only:
            return {
                'name': nm.strip(),
                'symbol': sm.strip(),
                'atomic_number': an.strip(),
            }

        return nm.strip()