Smart type casting in python
问题 I am making api calls and receive a response back in json like so result = {'foo': '123.456', 'bar': '23', 'donald': 'trump', 'time': '2016-04-07T05:31:49.532124Z'} Although result is either a dictionary or a list, the contents are always strings. I want to cast these values to the appropriate type. (i.e. '123.456' to a float, '23' to an int, 'time' to a datetime.) My code works but it seems like there should be a simpler/more efficient way to do this. Is there? Here's my version from