def __setitem__(self, indices, values):
        """Implement ``self[indices] = values``."""
        # Get the parts to which we assign values
        if isinstance(indices, Integral):
            indexed_parts = (self.parts[indices],)
            values = (values,)
        elif isinstance(indices, slice):
            indexed_parts = self.parts[indices]
        elif isinstance(indices, list):
            indexed_parts = tuple(self.parts[i] for i in indices)
        elif isinstance(indices, tuple):
            if len(indices) == 0:
                return
            else:
                # We need to explicitly use __setitem__ here, otherwise
                # __getitem__ is used and assigned to, which fails if
                # a space like rn(3) is indexed at the very end.
                part = self.parts[indices[0]]
                if isinstance(part, LinearSpaceElement):
                    part.__setitem__(indices[1:], values)
                else:
                    # part is a tuple
                    for p in part:
                        p.__setitem__(indices[1:], values)
                return
        else:
            raise TypeError('bad index type {}'.format(type(indices)))

        # Do the assignment, with broadcasting if desired
        try:
            iter(values)
        except TypeError:
            # `values` is not iterable, assume it can be assigned to
            # all indexed parts
            for p in indexed_parts:
                p[:] = values
        else:
            # `values` is iterable; it could still represent a single
            # element of a power space.
            if self.space.is_power_space and values in self.space[0]:
                # Broadcast a single element across a power space
                for p in indexed_parts:
                    p[:] = values
            else:
                # Now we really have one assigned value per part
                if len(values) != len(indexed_parts):
                    raise ValueError(
                        'length of iterable `values` not equal to number of '
                        'indexed parts ({} != {})'
                        ''.format(len(values), len(indexed_parts)))
                for p, v in zip(indexed_parts, values):
                    p[:] = v
def __setitem__ ( self , indices , values ) : if isinstance ( indices , Integral ) : indexed_parts = ( self . parts [ indices ] , ) values = ( values , ) elif isinstance ( indices , slice ) : indexed_parts = self . parts [ indices ] elif isinstance ( indices , list ) : indexed_parts = tuple ( self . parts [ i ] for i in indices ) elif isinstance ( indices , tuple ) : if len ( indices ) == 0 : return else : part = self . parts [ indices [ 0 ] ] if isinstance ( part , LinearSpaceElement ) : part . __setitem__ ( indices [ 1 : ] , values ) else : for p in part : p . __setitem__ ( indices [ 1 : ] , values ) return else : raise TypeError ( 'bad index type {}' . format ( type ( indices ) ) ) try : iter ( values ) except TypeError : for p in indexed_parts : p [ : ] = values else : if self . space . is_power_space and values in self . space [ 0 ] : for p in indexed_parts : p [ : ] = values else : if len ( values ) != len ( indexed_parts ) : raise ValueError ( 'length of iterable `values` not equal to number of ' 'indexed parts ({} != {})' '' . format ( len ( values ) , len ( indexed_parts ) ) ) for p , v in zip ( indexed_parts , values ) : p [ : ] = v
Implement ``self[indices] = values``.