I am trying to get a list of lists through this function in python, when I run it I only get back the last list L. How can I edit my code so that each iteration is saved in a common list? Thank you in advance
FB = []
while True:
given_name = input("Hva er fornavnet ditt? ")
if given_name == 'done':
break
surname = input("Hva er etternavnet ditt? ")
age = int(input("Hvor gammel er du? "))
gender = input("Hvilket kjønn har du? ")
def add_data():
L = []
L.append(given_name)
L.append(surname)
L.append(age)
L.append(gender)
return L
add_data()
FB.append(add_data())
print(FB)
FB.append(add_data())needs to be inside the loop, in place of your currentadd_data()line that just throws away its result.Lbut don't add l to FB until after loop.