Interchange values and keys in OrderedDict Python
Question: Here is my OrderedDict

    
    
    o=OrderedDict([('xmllist', 123), ('A', 124), ('B', 125), ('C', 126), ('D', 127)])
    

How can i interchange its keys and values as ,

    
    
    o=OrderedDict([('A', 123), ('B', 124), ('C', 125), ('D', 126)])
    


Answer: Using
[`zip`](http://docs.python.org/3/library/itertools.html#itertools.islice) and
[`itertools.islice`](http://docs.python.org/3/library/itertools.html#itertools.islice):

    
    
    >>> from collections import OrderedDict
    >>> import itertools
    >>>
    >>> o = OrderedDict([('xmllist', 123), ('A', 124), ('B', 125), ('C', 126), ('D', 127)])
    >>> OrderedDict((key1, o[key2]) for key1, key2 in zip(itertools.islice(o, 1, None), o))
    OrderedDict([('A', 123), ('B', 124), ('C', 125), ('D', 126)])
    

mapping: `o['A'] = o['xmllist']`, `o['B'] = o['A']`, `o['C'] = o['B']`, ...

