0
Python - Adding a list to a list
Hello, I am new to python and was wondering how I would code to add a person to a list. E.g i have a big list with all the clubs in it. Iâd ask the user to input their name and a club. If the personâs name is in a club, it would add the person to the club List but if the club does not exist, it would say the club doesnât exist. If the person gets added to a club e.g Choir, I want to also be able to Print the masterlist of all the people In all the clubs, not just a person In the Choir club. We have to do this without using classes and objects. Is this possible? Thanks :)
3 Answers
+ 4
Not entirely sure what youâre asking, but a large list of lists can get hard to manage, you may instead consider using a dictionary of lists, here are a few examples and methods to get your juices flowing.
clubs = {"Choir":[],"Chess":[]}
clubs["Choir"].append("John")
print("John" in clubs["Chess"])
print("John" in clubs["Choir"])
print(clubs)
print(clubs.keys())
print(clubs.values())
print(clubs.get("Choir"))
+ 1
Unclear. You would add a person to a club list if this club list has that person in it? Or do you have any other lists of persons to refer to?
+ 1
I'd do it like Jake, with a dictionary for the clubs, because then you can access them by name.