Why is the ipython output of set different from the __repr__ or __str__ of the set?
Question: I am running the following code in ipython and am surprised at the print
outputs and the ipython cell outputs of the code:

    
    
    print set(["A", "B", "C"])
    print set(["A", "C", "B"])
    print list(set(["A", "C", "B"]))
    print list(set(["A", "B", "C"]))
    print [k for k in set(["A", "C", "B"])]
    print [k for k in set(["A", "B", "C"])]
    a = set(["A", "B", "C"])
    print a
    print a.__repr__()
    print a.__str__()
    print [(k, hash(k)) for k in a]
    a
    

The output of the above program is as follows:

    
    
    set(['A', 'C', 'B'])
    set(['A', 'C', 'B'])
    ['A', 'C', 'B']
    ['A', 'C', 'B']
    ['A', 'C', 'B']
    ['A', 'C', 'B']
    set(['A', 'C', 'B'])
    set(['A', 'C', 'B'])
    set(['A', 'C', 'B'])
    [('A', -269909568), ('C', -13908798), ('B', -141909181)]
    Out[34]: {'A', 'B', 'C'}
    

Note, that the cell output is `{'A', 'B', 'C'}` while the printed output is
`set(['A', 'C', 'B'])`

My Python details are as follows:

    
    
    import sys
    print sys.version
    2.7.11 |Anaconda 2.3.0 (64-bit)| (default, Jan 29 2016, 14:26:21) [MSC v.1500 64 bit (AMD64)]
    


Answer: IPython adds some magic from time-to-time to make things more readable.

In this case it's showing you a set literal (new in python2.7)

Here's the code that makes that happen:

<https://github.com/ipython/ipython/blob/f49962dc931870a1eba4b6467ce302c8ae095b3f/IPython/lib/pretty.py#L560>

