python - Skip a letter in dictionary -


i need assign uppercase numbers in dictionary 1 letter s not there.

ie.

in alphadict = dict((x, i) i, x in enumerate(string.ascii_uppercase)) have alphabets of dictionary.

what simplest way delete entry s , shift rest of values left.

if there other way create dictionary tell.....


i in need of this..... number user..... number in dictionary should assigned s , other dictionary items can readjusted....

ie user gives me 3 dictionary should like

0- 1- b 2- c 3- s , rest follow d z without s.......

please help..... lot....

if understand properly, simplest thing seems first create list letters in order want, , convert dictionary:

import string  sans_s = [c c in string.ascii_uppercase if c not 's'] user_choice = 3 alphabet = sans_s[0:user_choice] + ['s'] + sans_s[user_choice:]  print alphabet # ['a', 'b', 'c', 's', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', #  'o', 'p', 'q', 'r', 't', 'u', 'v', 'w', 'x', 'y', 'z']  # create dictionary using modified list alphadict = dict((x, i) i, x in enumerate(alphabet))  # print out alphadict sorted item values (not necessary part of answer) revdict = dict( (v,k) k,v in alphadict.iteritems() ) print '{', v in sorted(alphadict.itervalues()):     print "%r:%2d," % (revdict[v], v), print '}'  # { 'a': 0, 'b': 1, 'c': 2, 's': 3, 'd': 4, 'e': 5, 'f': 6, 'g': 7, 'h': 8, #   'i': 9, 'j':10, 'k':11, 'l':12, 'm':13, 'n':14, 'o':15, 'p':16, 'q':17, #   'r':18, 't':19, 'u':20, 'v':21, 'w':22, 'x':23, 'y':24, 'z':25, } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -