Search code examples
pythonnested-lists

Appending to List Eror


I'm new to Python and am struggling with the syntax to join a new value to a list and then add that to a list of lists. loc_ref and from_loc are both pre-existing lists and user_says is a user input field using user_says = input("Enter Data")

print(loc_ref,"\n")  #returns [['COMPANY|ADDRESS|CITY|STATE|LOCATION']] 
print(from_loc,"\n") #returns ['COMPANY A', '1515 STREET RD', 'CITYA', 'ST'] 
print([user_says])
loc_ref = loc_ref.append(from_loc + [user_says]) 
print(loc_ref)  #returns None 

Why is loc_ref returning None ?


Solution

  • You're setting the value of loc_ref to None

    loc_ref = loc_ref.append(from_loc + [user_says])

    list.append does not return the list with the appended value, it returns None, as a result, loc_ref is set to None

    Try just: loc_ref.append(from_loc + [user_says]) and get rid of the loc_ref =