timeit

Програмиране с Python

Курс във Факултета по Математика и Информатика към СУ

Решение на Социална мрежа от Вера Бойчева

Обратно към всички решения

Към профила на Вера Бойчева

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 0 неуспешни тест(а)

Код

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from uuid import uuid
from datetime import datetime

class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def unfollow(self, follower, followee):
        graph.follow_data[followee].discard(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  
    def friends(self, user_uuid):
        result = set()
        for key, value in graph.social_graph.items():
            if user_uuid in value:
                result.add(key)
        return result

class User:
    
    
    def __init__(self, full_name):
        self.full_name = full_name
        self.id = uuid.uuid4()
        self.counter = 0
        slef.posts = []






Лог от изпълнението

cannot import name 'uuid'
  File "/data/rails/pyfmi-2016/releases/20160307095126/lib/language/python/runner.py", line 114, in main
    loaded_test = imp.load_source('test', test_module)
  File "/usr/local/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/tmp/d20160530-24280-tofi9f/test.py", line 4, in <module>
    import solution
  File "/tmp/d20160530-24280-tofi9f/solution.py", line 1, in <module>
    from uuid import uuid

История (14 версии и 0 коментара)

Вера обнови решението на 18.04.2016 16:45 (преди над 1 година)

1
2
3
4
5
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

Вера обнови решението на 18.04.2016 16:46 (преди над 1 година)

1
2
3
4
5
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

Вера обнови решението на 18.04.2016 16:47 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content
class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

Вера обнови решението на 18.04.2016 16:47 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)

Вера обнови решението на 18.04.2016 16:49 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)        

Вера обнови решението на 18.04.2016 16:51 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)      
        

Вера обнови решението на 18.04.2016 16:55 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee] 
        

Вера обнови решението на 18.04.2016 16:55 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        

Вера обнови решението на 18.04.2016 16:56 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  

Вера обнови решението на 18.04.2016 16:56 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  
    def friends(self, user_uuid):
        result = set()
        for key, value in graph.social_graph.items():
            if user_uuid in value:
                result.add(key)
        return result

Вера обнови решението на 18.04.2016 16:56 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def unfollow(self, follower, followee):
        graph.follow_data[followee].discard(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  
    def friends(self, user_uuid):
        result = set()
        for key, value in graph.social_graph.items():
            if user_uuid in value:
                result.add(key)
        return result

Вера обнови решението на 18.04.2016 16:56 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def unfollow(self, follower, followee):
        graph.follow_data[followee].discard(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  
    def friends(self, user_uuid):
        result = set()
        for key, value in graph.social_graph.items():
            if user_uuid in value:
                result.add(key)
        return result

class User:
    posts = {}
    
    def __init__(self, full_name):
        self.full_name = full_name
        self.id = uuid.uuid4()
        self.counter = 0
        slef.posts = []

Вера обнови решението на 18.04.2016 16:57 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from uuid import uuid
from datetime import datetime

class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def unfollow(self, follower, followee):
        graph.follow_data[followee].discard(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  
    def friends(self, user_uuid):
        result = set()
        for key, value in graph.social_graph.items():
            if user_uuid in value:
                result.add(key)
        return result

class User:
    posts = {}
    
    def __init__(self, full_name):
        self.full_name = full_name
        self.id = uuid.uuid4()
        self.counter = 0
        slef.posts = []




Вера обнови решението на 18.04.2016 16:59 (преди над 1 година)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from uuid import uuid
from datetime import datetime

class Post:
    def __init__(self, author, published_at, content):
        self.__author= author
        self.__published_at = published_at
        self.__content = content

class graph:
    users = {}
    social_graph= {}
    follow_data={}
    def add_user(self, user):
        users[user.id]=user

    def get_user(self, user_uuid):
        return users[user_uuid]

    def delete_user(self, user_uuid):
        users = {key: value for key, value in users.items() 
             if key is not user_uuid}
        social_graph = {key: value for key, value in social_graph.items() 
             if key is not user_uuid}
        follow_data = {key: value for key, value in follow_data.items() 
             if key is not user_uuid}
        for key, value in social_graph.items():
            value.discard(user_uuid)
        for key, value in follow_data.items():
            value.discard(user_uuid)
    def follow(self, follower, followee):
        graph.follow_data[followee].add(follower)
    def unfollow(self, follower, followee):
        graph.follow_data[followee].discard(follower)
    def is_following(self, follower, followee):
        return follower in graph.follow_data[followee]
    def followers(self, user_uuid):
        return graph.follow_data[user_uuid] 
        
    def following(self, user_uuid):
        result = set()
        for key, value in graph.follow_data.items():
            if user_uuid in value:
                result.add(key)
        return result  
    def friends(self, user_uuid):
        result = set()
        for key, value in graph.social_graph.items():
            if user_uuid in value:
                result.add(key)
        return result

class User:
    
    
    def __init__(self, full_name):
        self.full_name = full_name
        self.id = uuid.uuid4()
        self.counter = 0
        slef.posts = []