Question: I have a live video stream from FFMpeg, and I am having a hard time viewing the stream using my own custom Java application. Before someone tells me to use VLC or something like that I do want to use my own application. The stream I am trying to read is a H.264 encoded Mpeg-ts stream streamed over UDP. I do know how to decode the H.264 frames, but I am simply wondering about how to receive the Mpeg-ts stream.

Answer: 
I found a relatively simple solution for this, but it includes the risk of making the output for your ordered dictionary appear exactly as if it were a regular `dict` object.

The original solution for using a context manager to prevent `pprint` from sorting dictionary keys comes from [this answer](https://stackoverflow.com/a/25688431/3637954).

```
@contextlib.contextmanager
def pprint_OrderedDict():
    pp_orig = pprint._sorted
    od_orig = OrderedDict.__repr__
    try:
        pprint._sorted = lambda x:x
        OrderedDict.__repr__ = dict.__repr__
        yield
    finally:
        pprint._sorted = pp_orig
        OrderedDict.__repr__ = od_orig

```

(You could also just patch the `OrderedDict.__repr__` method with `dict.__repr__`, but please don't.)

Example:

```
>>> foo = [('Roger', 'Owner'), ('Diane', 'Manager'), ('Bob', 'Manager'),
...        ('Ian', 'Associate'), ('Bill', 'Associate'), ('Melinda', 'Associate')]

>>> d = OrderedDict(foo)
>>> pprint.pprint(d)
OrderedDict([('Roger', 'Owner'), ('Diane', 'Manager'), ('Bob', 'Manager'), ('Ian', 'Associate'), ('Bill', 'Associate'), ('Melinda', 'Associate')])

>>> pprint.pprint(dict(d))
{'Bill': 'Associate',
 'Bob': 'Manager',
 'Diane': 'Manager',
 'Ian': 'Associate',
 'Melinda': 'Associate',
 'Roger': 'Owner'}

>>> with pprint_OrderedDict():
...     pprint.pprint(d)
...
{'Roger': 'Owner',
 'Diane': 'Manager',
 'Bob': 'Manager',
 'Ian': 'Associate',
 'Bill': 'Associate',
 'Melinda': 'Associate'}

```
If you are specifically targeting CPython\* 3.6 or later, then you can [just use regular dictionaries](https://docs.python.org/3.6/whatsnew/3.6.html#whatsnew36-compactdict) instead of `OrderedDict`. You'll miss out on a few [methods exclusive to `OrderedDict`](https://docs.python.org/3.6/library/collections.html#collections.OrderedDict), and this is not (yet) guaranteed to be portable to other Python implementations,\*\* but it is probably the simplest way to accomplish what you are trying to do.

\* CPython is the reference implementation of Python which may be downloaded from python.org.  

\*\* CPython [stole this idea from PyPy](https://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html), so you can probably depend on it working there too.