python - Formatting issue involving lists -


i've got function takes name input, puts list , runs ord() against it. however, having (what believe) formatting issues. i'm trying appear so:

b = (ascii value) = (ascii value) t = (ascii value) m = (ascii value) = (ascii value) n = (ascii value) 

i've got name appearing correctly, ascii value appearing this:

b = [98, 97, 116, 109, 97, 110] = [98, 97, 116, 109, 97, 110] t = [98, 97, 116, 109, 97, 110] m = [98, 97, 116, 109, 97, 110] = [98, 97, 116, 109, 97, 110] n = [98, 97, 116, 109, 97, 110] 

not sure i'm going wrong, below code i've made it:

def x():      name = requeststring("name")      usersname = list(name)      ascii = [orc(c) c in usersname]      name in name:            print name, "=", ascii  

thanks!

edit: thanks, it's appreciated. went wrong now!

here's bit of review of went wrong:

def x():      name = requeststring("name")      usersname = list(name)      ascii = [orc(c) c in usersname] # here's list      name in name:            print name, "=", ascii # , you're printing here everytime 

you fix more pythonically this:

def x():      name = requeststring("name")      # usersname = list(name) # no need line, can iterate on string      ascii = [orc(c) c in name] #so name      i, c in enumerate(name):  # use c character var name,            print c, "=", ascii[i]   # , enumerate provides index 

since you're not returning anything, creating list unnecessary, might provide ord(c) on fly:

def print_ords_of_word(name):     c in name:         print c, '=', ord(c) 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -