So I'm not sure if the title even makes sense but basically I have a class that keeps track of friends (like an address book), and I'm at the part where I need to create a function that adds friends to a set of existing names. So I've got the beginning of my code as:
class SocialAddressBook:
def __init__(self):
self.book= []
def addName(self, name, address):
self.book.append([name, address, set()])
"""Adds name to address book, with address and no friends"""
which runs fine. and then the part that gives me 'list' object has no attribute 'list' error:
def addFriend(self, name, friend):
for k in range(len(self.book.list[k])):
if self.book[k][0] == name:
my idea was to iterate over a list and add onto the existing list, but syntax is definitely throwing me for a loop (no pun intended) and I'm not sure how I should go about this now.
some test code:
a.addFriend('Fred', 'Barb'); a.addFriend('Fred', 'Sue')
a.addFriend('Barb', 'Jane'); a.addFriend('Jane', 'Emma')
a.addFriend('Jane', 'Mary'); a.addFriend('Emma', 'Lisa')
Thank you!
self.book.list, I think think lists have alistproperty.for book_name, address, friends in self.book:and thenif book_name == name:would do, depending on what comes after. Probablyfriends.add(friend)?