I would like to give some feedback about ...
From: https://checkio.org/mission/friends/solve/
class Friends:
def init(self, connections):
print(connections);
self.connections = connections;
def add(self, connection):
if connection in self.connections:
return False
else:
self.connections = list(self.connections);
self.connections.append(connection);
return True
def remove(self, connection):
deleted = False;
for elem in self.connections:
if str(elem) == str(connection):
print(type(self.connections));
print("test1:");
print(self.connections);
self.connections.remove(elem);
print("test2:");
print(self.connections);
deleted = True;
return deleted
def names(self):
result = []
for elem in self.connections:
for x in elem:
result.append(x)
result = set(result);
print("result:");
print(result);
return result
def connected(self, name):
new_list = [];
new_list2 = [];
print("name: " + name);
check = False;
for elem in self.connections:
for item in elem:
item_buffer = item;
print("item: " + item);
if check == True:
new_list2.append(item);
check = False;
#item_buffer.append(item);
if item == name:
print("same!");
#new_list2.append(item_buffer);
check = True;
new_list.append(item);
item_buffer = ();
print("new_list:");
print(new_list);
print("new_list2:");
print(new_list2);
print(set(new_list2));
return set(new_list2);
if name == 'main':
#These "asserts" using only for self-checking and not necessary for auto-testing
letterfriends = Friends(({"a", "b"}, {"b", "c"}, {"c", "a"}, {"a", "c"}))
digitfriends = Friends([{"1", "2"}, {"3", "1"}])
assert letterfriends.add({"c", "d"}) is True, "Add"
assert letterfriends.add({"c", "d"}) is False, "Add again"
assert letterfriends.remove({"c", "d"}) is True, "Remove"
assert digitfriends.remove({"c", "d"}) is False, "Remove non exists"
assert letterfriends.names() == {"a", "b", "c"}, "Names"
assert letterfriends.connected("d") == set(), "Non connected name"
assert letter_friends.connected("a") == {"b", "c"}, "Connected name"
HTTP_USER_AGENT:
Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:47.0) Gecko/20100101 Firefox/47.0
Please check if it is your test or my code,
I have no idea why the "remove()" cannot be used?
All the best
AttributeError: 'tuple' object has no attribute 'remove', remove, 22, , 7
f = Friends(({"nikola", "sophia"}, {"stephen", "robot"}, {"sophia", "pilot"})) f.remove({"stephen", "robot"}) f.names()
Created at: 2016/07/28 13:13; Updated at: 2016/08/01 11:28