Python Forum
Kevin Bacon game with breath-first search
Thread Rating:
  • 2 Vote(s) - 4.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Kevin Bacon game with breath-first search
#3
There are a couple ways to correct this. The first way is calling the cvor's attribute that stores the name (ime, I believe):

for movie in graf:
    print(movie.ime)
To simplify that, you could create a function that does the same thing and use map():

def return_movie_name(movie):
    return movie.ime

print(map(return_movie_name, graf))
Or, you can add __str__() and __repr__() methods to cvor to return the movie name when the object is printed:

class cvor:
    __slots__ = ('ime','susjed')

    def __str__(self):
        return self.ime

    def __repr__(self):
        return self.__str__()

print(graf)
Reply


Messages In This Thread
RE: Kevin Bacon game with breath-first search - by stullis - Jan-09-2019, 03:05 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020