On Wed, 22 Oct 2014 16:57:00 -0400, Joel Goldstick <joel.goldst...@gmail.com> wrote:
>On Wed, Oct 22, 2014 at 4:30 PM, Seymore4Head ><Seymore4Head@hotmail.invalid> wrote: >> def nametonumber(name): >> lst=[""] >> for x,y in enumerate (name): >> lst=lst.append(y) >> print (lst) >> return (lst) >> a=["1-800-getcharter"] >> print (nametonumber(a))#18004382427837 >> >> >> The syntax for when to use a () and when to use [] still throws me a >> curve. >() is tuples which are immutable which means that the items can't be >changed. [] is list which means that each item can be changed. >Tuples are useful because they can be used as keys in dictionaries and >are guarantied not to change. Lists are useful because they can be >updated. > >What you are doing confuses me. You don't use x, which is the enumerated >value. > >FIrst lst should be lst = [] . You don't need to set the first >element in the list to an empty string. You just want to establish >that you have an empty list called lst >Second, you don't need lst = lst.append(y) because you can just say >lst.append(y). This will append the y value to the end of the list. >As to converting letters to the corresponding numbers on a phone >keypad, you don't show you code here for that >> >> For now, I am trying to end up with a list that has each character in >> "a" as a single item. >> >> I get: >> None >> None >> -- >> https://mail.python.org/mailman/listinfo/python-list The lst=lst.append(y) Was the mistake I never could see. I am using enumerate just for practice. To me that is just as easy as typing len(something) and it seems more flexible. and.......the reason I don't show the code for the conversions is that I haven't got that far yet. :) Thank you -- https://mail.python.org/mailman/listinfo/python-list