Reputation: 9
How would I append to a 2D list using a user input if my list was
superheroes = [["Superman", "flying"],
["Spiderman", "web"],
["Batman", "Technology"],
["Wonder woman","Lasso of Truth"]]
Upvotes: 0
Views: 8513
Reputation: 25895
Like you append to any list:
superheroes += [["Green lantern","A green lantern..."]]
or
superheroes.append(["Green lantern","A green lantern..."])
Upvotes: 2
Reputation: 1258
You could do the following
temp = []
name = input("Enter Superhero's name")
temp.append(name)
type = input("Enter Superhero's type")
temp.append(type)
superheroes.append(temp)
This would ask the user for inputs for both the name and type of the superhero and add a list of those in your existing list.
Another way of king the user input and updating your list, in one line:
superheroes.append([input("Enter superhero's name"),input("Enter superhero's type")])
Upvotes: 0