python - how to iterate from index n to m of an OrderedDict? -
this question has answer here:
- slicing python ordereddict 5 answers
i have ordereddict
, iterate on subset of elements, index n
m
.i can simple way:
from collections import ordereddict d = ordereddict() in range(10): d[i] = n = 3 m = 6 c = 0 in d: if n <= c <= m: print(d[i]) c += 1
but looking more compact, similar slicing lists:
n = 3 m = 6 l = [i in range(10)] in l[n:m+1]: print(i)
is there such mechanism ordereddict
?
it depends on how ordereddict
created (n
, m
need consider index of items in d
), how this:
d.values()[n:m]
Comments
Post a Comment