list in loop, Nonetype errors
- by user2926755
Here is my Code
def printList(stringlist):
empty = []
if stringlist is None:
print empty
else:
print stringlist
def add (stringlist, string):
string = [] if string is None else string
if stringlist is not None:
stringlist.insert(0, string)
else:
stringlist.append(1)
it somehow appears "AttributeError: 'NoneType' object has no attribute 'append'"
I was originally looking for the code to be run like this:
>>> myList = None
>>> printList(myList)
[]
>>> for word in ['laundry','homework','cooking','cleaning']:
myList = add(myList, word)
printList(myList)
[laundry]
[homework, laundry]
[cooking, homework, laundry]
[cleaning, cooking, homework, laundry]