I am out of trial and error again Lists

Denis McMahon denismfmcmahon at gmail.com
Thu Oct 23 11:21:44 CEST 2014


On Wed, 22 Oct 2014 19:11:51 -0400, Seymore4Head wrote:

> On Wed, 22 Oct 2014 22:43:14 +0000 (UTC), Denis McMahon
> <denismfmcmahon at gmail.com> wrote:
> 
>>On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head 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.
>>> 
>>> 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
>>
>>First of all, an empty list is created with:
>>
>>emptylist = []
>>
>>whereas
>>
>>x = [""]
>>
>>creates a list containing one element, that element being an empty
>>string. Not the same thing!
>>
>>Did you try stepping through your code line by line in the interpreter
>>to see what happened at each step?
>>
>>note that append is a method of a list object, it has no return value,
>>the original list is modified in place.
>>
>>>>> l = ["a","b","c"]   # declare a list l.append( "d" )     # use the
>>>>> append method l                   # show the list
>>['a', 'b', 'c', 'd']
>>
>>So your line:
>>
>>lst = lst.append(y)
>>
>>should be:
>>
>>lst.append(y)
>>
>>Finally, did you really intend to pass a single element list into the
>>function, or did you intend to pass a string into the function?
>>
> Those string errors were desperate attempts to fix the "append" error I
> didn't understand.

If you don't understand the error, that is the point that you should ask 
for help, rather than make stab in the dark attempts to fix it and then 
asking why the solutions don't work.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list