0
How can I fix this?
list1 = [1, 2, 3] again = 'y' while again == 'y': number = input("Enter a number: ") print("Is there another?") again = input("Enter y for yes or n for no: ") #Add input values onto the list list1.append([number] * 2) I want: list1 = [1, 2, 3, 4, 4, 5, 5, 6, 6] What I'm getting is: list1 = [1, 2, 3, [4, 4], [5, 5], [6, 6]]
2 Respostas
0
list1.append(number) ?
0
Use extend() instead of append().
lst = [1, 2, 3]
lst.extend([4]*2)
print(lst)
# [1, 2, 3, 4]