dictionary - Splitting a python dict from a certain key -


i'm trying split dict point in dict. seemed doing simple items_dict[3:] work did not work.

items_dict = {     "cannon barrels":10,     "cannon furnace":12,     "candle":36,     "bronze arrowheads":39,     "iron arrowheads":40,     "steel arrowheads":41,     "mithril arrowheads":42,     "adamant arrowheads":4 } print items_dict[3:] # nope, won't work print items_dict["candle"] # of course, returns candle's number 

i figured out how to slice dictionary keys start string, want know how slice dictionary similar list.

if want split after n keys - no guarantee on order.

n=3 d1 = {key: value i, (key, value) in enumerate(d.items()) if < n} d2 = {key: value i, (key, value) in enumerate(d.items()) if >= n} 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -