python truncating a dictionary to get last elements -


i have python dictionary of form:

{"1":"sdv","2":"wefc","3":"sdsdv","4":"dvsdv","5":"igsdhc","6":"gvvxas","7":"sdvsfdv","8":"sdagf"} 

i need remove first 6 elements in dictionary , take remaining once only. length of list may vary greater 6.

please me

the dictionary doesn't have ordering in keys. can take keys, sort them, , manually remove first 6 of them:

d = {    "1":"sdv","2":"wefc","3":"sdsdv","4":"dvsdv",    "5":"igsdhc","6":"gvvxas","7":"sdvsfdv","8":"sdagf" }  key in sorted(d, key=int)[:6]:     del d[key]  print d     

result:

 {'7': 'sdvsfdv', '8': 'sdagf'} 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -