• misunderstanding set operations


Hello world

I have difficulties handling sets. My code below iterates through the class its list of connections (self.friends), and inside there through the sets of connections. if found the name given by method 'connected', I would like to have only the paired item; if found "nikola" in {"nikola", "sophia"}, we need just "sophia".

    def connected(self, name):
        for connection in self.friends:
            for friend in connection:
                if name in friend:
                    #return connection
                    return connection.remove(name)

What is wrong with me, I can return {"nikola", "sophia"}, but don't find a way by now to substract our dear "nikola". I would be happy to get a reference whereas I can read specific the overall technique I'm missing. In the python docs for list/set comprehensions I didn't find it so far. When I try with minus it's error 'caus set and str, changing the str to set splits the word in single characters. oh my ^.^

Have a nice evening :)