def set_levels(self, levels, level=None, inplace=False,<EOL>verify_integrity=True):
if is_list_like(levels) and not isinstance(levels, Index):<EOL><INDENT>levels = list(levels)<EOL><DEDENT>if level is not None and not is_list_like(level):<EOL><INDENT>if not is_list_like(levels):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if is_list_like(levels[<NUM_LIT:0>]):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>level = [level]<EOL>levels = [levels]<EOL><DEDENT>elif level is None or is_list_like(level):<EOL><INDENT>if not is_list_like(levels) or not is_list_like(levels[<NUM_LIT:0>]):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT><DEDENT>if inplace:<EOL><INDENT>idx = self<EOL><DEDENT>else:<EOL><INDENT>idx = self._shallow_copy()<EOL><DEDENT>idx._reset_identity()<EOL>idx._set_levels(levels, level=level, validate=True,<EOL>verify_integrity=verify_integrity)<EOL>if not inplace:<EOL><INDENT>return idx<EOL><DEDENT>
Set new levels on MultiIndex. Defaults to returning
new index.

Parameters
----------
levels : sequence or list of sequence
    new level(s) to apply
level : int, level name, or sequence of int/level names (default None)
    level(s) to set (None for all levels)
inplace : bool
    if True, mutates in place
verify_integrity : bool (default True)
    if True, checks that levels and codes are compatible

Returns
-------
new index (of same type and class...etc)

Examples
--------
>>> idx = pd.MultiIndex.from_tuples([(1, 'one'), (1, 'two'),
                                    (2, 'one'), (2, 'two')],
                                    names=['foo', 'bar'])
>>> idx.set_levels([['a','b'], [1,2]])
MultiIndex(levels=[['a', 'b'], [1, 2]],
           codes=[[0, 0, 1, 1], [0, 1, 0, 1]],
           names=['foo', 'bar'])
>>> idx.set_levels(['a','b'], level=0)
MultiIndex(levels=[['a', 'b'], ['one', 'two']],
           codes=[[0, 0, 1, 1], [0, 1, 0, 1]],
           names=['foo', 'bar'])
>>> idx.set_levels(['a','b'], level='bar')
MultiIndex(levels=[[1, 2], ['a', 'b']],
           codes=[[0, 0, 1, 1], [0, 1, 0, 1]],
           names=['foo', 'bar'])
>>> idx.set_levels([['a','b'], [1,2]], level=[0,1])
MultiIndex(levels=[['a', 'b'], [1, 2]],
           codes=[[0, 0, 1, 1], [0, 1, 0, 1]],
           names=['foo', 'bar'])