Python dictionaries in the interactive interpreter


#1

This is not a revelation by any length, but I thought it worth sharing. Python dictionaries are handy containers for running data when we just want to do some console math. Once the console fills up with inputs and outputs, it can be a mess. Running individual variables during the process means having to scroll up and down to find them, and their state.

Consider the following investigation into Neptune:

>>> neptune = {'km': 4498252900, 'mi': 2795084800, 'au': {'km': 1.5e8, 'mi': 9.3e7 }}

The au member is a fudge, but for my purposes keeps all the data in one object since I know this data will be needed.

>>> neptune['au_km'] = neptune['km'] / neptune['au']['km']
>>> neptune['au_mi'] = neptune['mi'] / neptune['au']['mi']
>>> au = neptune.pop('au')
>>> neptune
{'km': 4498252900, 'au_mi': 30.054675268817203, 'mi': 2795084800, 'au_km': 29.988352666666668}

Still pretty rough around the edges but the data is accumulating on the one object.

>>> neptune['au_x'] = int((neptune['au_mi'] + neptune['au_km']) / 2)
>>> neptune
{'au_x': 30, 'au_mi': 30.054675268817203, 'au_km': 29.988352666666668, 'mi': 2795084800, 'km': 4498252900}
>>>

Now we have a simple piece of data to find what "20 times the distance to Neptune from the sun," actually means: 20 * 30 * 150000000 kilometers, or 600 AU.

This is the distance to a planet that CALTECH astromers are convinced is out there. it is said to be

>>> 6e2*1.5e8
90000000000.0
>>>

90 billion kilometers from the sun. Given a distance, we can estimate its orbit time using Keplar's Third Law.

Te^2 / Re^3 = Tx^2 / Rx^3

1 / 1 = Tx^2 / 600^3

600^3 = Tx^2

Tx = 1.47e4

The estimate is between 10 and 20 thousand years. This jives. With a little more effort we could add this relational data to the dictionary and keep all our data still contained in one object.

Maybe not very useful on the grand scale, but for sure a way to work in a pinch.