In [1]:
import json
In [3]:
example_data = {"some": [{"horrible":"0", "terrible": {"nested":["really", "nested", {"thing": 5} ]}},{1:2}]}
In [4]:
example_data
Out[4]:
In [5]:
print(json.dumps(example_data, sort_keys = True, indent = 4))
In [6]:
def pretty(data):
print(json.dumps(data, sort_keys = True, indent = 4))
In [7]:
pretty(example_data["some"])
In [8]:
pretty(example_data["some"][0])
In [9]:
pretty(example_data["some"][0]["terrible"])
In [10]:
pretty(example_data["some"][0]["terrible"]["nested"])
In [18]:
list_of_cats = [{"a": 5, "name": "biter"}, {"a": 15, "name": "beater"}, {"a": 50, "name": "felix"}, {"a": 500, "name": "garfield"}, {"a": 0.55, "name": "fluff"}]
In [14]:
print(list_of_cats[0])
In [15]:
print(list_of_cats[0]["a"])
In [19]:
chonkiest = list_of_cats[0]
for chonky_cat in list_of_cats:
looking_at = chonky_cat["a"]
if looking_at > chonkiest["a"]:
chonkiest = chonky_cat
print(chonkiest["name"])
In [20]:
import datetime
In [21]:
print(datetime.datetime.now())
In [29]:
class Litigant(object):
def __init__(self, role, name):
self.role = role
self.name = name
In [30]:
class Lawsuit(object):
def __init__(self, plaintiff, defendant):
self.case_number = 50
self.plaintiff = Litigant(role="Plaintiff", name=plaintiff)
self.defendant = Litigant(role="Defendant", name=defendant)
def announce(self):
print(self.plaintiff.name + " v. " + self.defendant.name)
In [31]:
classroom_suit = Lawsuit("Madison", "Innocent Beleagured Professor")
In [32]:
classroom_suit.announce()
In [ ]: