OrderedDict in python 3 - how to get the keys in order?
问题 In python 2 when using an OrderedDict I was able to get the keys in the order they were inserted by simply using the keys method that returned a list. In python 3 however: rows = OrderedDict() rows[0]=[1,2,3] rows[1]=[1,2,3] image = [rows[k] for k in rows.keys()[:2]] I get: Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: 'odict_keys' object is not subscriptable I certainly can do list(rows)[:2] as advised for instance here - but is this guaranteed to get me