0

I want to remove the brackets and the apostrophes from a list that contains several strings. My code is -

list_of_libraries = []
class Library :
    def __init__(self, librarys_name, *listofbooks):
        self.listofbooks=listofbooks
        self.libraryname=librarys_name
        self.lent_list = []
        global list_of_libraries
        list_of_libraries.append(self.libraryname)
abcd = ["Harry Potter and the chamber of secrets", "Harry Potter and the philosophers stone"]
Gauravs_library = Library("Gaurav's library", abcd)
Larrys_books = ["Beginners python course", "Python game development course"]
Larrys_library = Library("Larry's library", Larrys_books)
print(list_of_libraries)

Output coming -

["Gaurav's library", "Larry's library"]

Desired output -

Gaurav's library, Larry's library
Gaurav
  • 3
  • 4
  • 1
    As a side note, `Library.listofbooks` may not be what you expect. Right now it will be nested one-element tuple of list of strings, rather than list of strings (books) - because of the asterisks. Not to mention the terribly awful idea to use global variable `list_of_libraries` inside the class. You should add instances of Library class to that list outside the class. – buran Mar 13 '22 at 16:35

0 Answers0