timeit

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

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

Решение на Работа с картинки от Славена Теодосиева

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

Към профила на Славена Теодосиева

Резултати

  • 10 точки от тестове
  • 0 бонус точки
  • 10 точки общо
  • 12 успешни тест(а)
  • 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
def rotate_left(image):
    return list(list(image[row][column] for row in range(len(image)))
                for column in range(len(image[0]) - 1, -1, -1))

def rotate_right(image):
    return list(list(image[row][column]
                    for row in range(len(image) - 1, -1, -1))
                for column in range(len(image[0])))

def invert(image):
    return list(list(tuple(255 - image[row][column][i] for i in range(3))
                    for column in range(len(image[0])))
                for row in range(len(image)))

def lighten(image, num):
    return list(list(tuple(image[row][column][i] +
                int(num * (255 - image[row][column][i])) for i in range(3))
                    for column in range(len(image[0])))
                for row in range(len(image)))

def darken(image, num):
    return list(list(tuple(image[row][column][i] -
                int(num * (image[row][column][i] - 0)) for i in range(3))
                    for column in range(len(image[0])))
                for row in range(len(image)))

def list_of_lists(image):
    list_ = []
    list_copy = []
    result_list = []
    for col in range(3):
        for row in range(len(image)):
            for column in range(len(image[0])):
                for i in range(256):
                    if i == image[row][column][col]:
                        list_.append((i, 1))
        list_copy = list_
        result_list.append(list_copy)
        list_ = []
    return result_list

def list_to_dict(list_for_each_color):
    color = {}
    for num, repeats in list_for_each_color:
        if num in color:
            color[num] = color[num] + repeats
        else:
            color[num] = repeats
    return color

def list_of_dicts(list_of_lists):
    return list(list_to_dict(every_list) for every_list in list_of_lists)

def create_histogram(image):
    colors = ['red', 'green', 'blue']
    return dict(zip(colors, list_of_dicts(list_of_lists(image))))

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

............
----------------------------------------------------------------------
Ran 12 tests in 0.101s

OK

История (3 версии и 1 коментар)

Славена обнови решението на 13.03.2016 01:37 (преди почти 2 години)

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
def rotate_left(image):
    return list(list(image[row][column] for row in range(len(image[0])))
    for column in range(len(image[0]) - 1, -1, -1))

def rotate_right(image):
    return list(list(image[row][column]
    for row in range(len(image[0]) - 1, -1, -1))
    for column in range(len(image[0])))

def invert(image):
    return list(list(tuple(255 - image[row][column][i] for i in range(3))
    for column in range(len(image[0]))) for row in range(len(image[0])))

def lighten(image, num):
    return list(list(tuple(image[row][column][i] +
    int(num * (255 - image[row][column][i])) for i in range(3))
    for column in range(len(image[0]))) for row in range(len(image[0])))

def darken(image, num):
    return list(list(tuple(image[row][column][i] -
    int(num * image[row][column][i]) for i in range(3))
    for column in range(len(image[0]))) for row in range(len(image[0])))

def list_of_lists(image):
    list_ = []
    list_copy = []
    result_list = []
    for col in range(3):
        for row in range(len(image[0])):
            for column in range(len(image[0])):
                for i in range(256):
                    if i == image[row][column][col]:
                        list_.append((i, 1))
        list_copy = list_
        result_list.append(list_copy)
        list_ = []
    return result_list

def list_to_dict(list_for_each_color):
    color = {}
    for num, repeats in list_for_each_color:
        if num in color:
            color[num] = color[num] + repeats
        else:
            color[num] = repeats
    return color

def list_of_dicts(list_of_lists):
    return list(list_to_dict(every_list) for every_list in list_of_lists)

def create_histogram(image):
    colors = ['red', 'green', 'blue']
    return dict(zip(colors, list_of_dicts(list_of_lists(image))))

Славена обнови решението на 13.03.2016 11:56 (преди почти 2 години)

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
def rotate_left(image):
    return list(list(image[row][column] for row in range(len(image)))
    for column in range(len(image[0]) - 1, -1, -1))

def rotate_right(image):
    return list(list(image[row][column]
    for row in range(len(image) - 1, -1, -1))
    for column in range(len(image[0])))

def invert(image):
    return list(list(tuple(255 - image[row][column][i] for i in range(3))
    for column in range(len(image[0]))) for row in range(len(image)))

def lighten(image, num):
    return list(list(tuple(image[row][column][i] +
    int(num * (255 - image[row][column][i])) for i in range(3))
    for column in range(len(image[0]))) for row in range(len(image)))

def darken(image, num):
    return list(list(tuple(image[row][column][i] -
    int(num * image[row][column][i]) for i in range(3))
    for column in range(len(image[0]))) for row in range(len(image)))

def list_of_lists(image):
    list_ = []
    list_copy = []
    result_list = []
    for col in range(3):
        for row in range(len(image)):
            for column in range(len(image[0])):
                for i in range(256):
                    if i == image[row][column][col]:
                        list_.append((i, 1))
        list_copy = list_
        result_list.append(list_copy)
        list_ = []
    return result_list

def list_to_dict(list_for_each_color):
    color = {}
    for num, repeats in list_for_each_color:
        if num in color:
            color[num] = color[num] + repeats
        else:
            color[num] = repeats
    return color

def list_of_dicts(list_of_lists):
    return list(list_to_dict(every_list) for every_list in list_of_lists)

def create_histogram(image):
    colors = ['red', 'green', 'blue']
    return dict(zip(colors, list_of_dicts(list_of_lists(image))))

Славена обнови решението на 14.03.2016 15:13 (преди почти 2 години)

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
def rotate_left(image):
    return list(list(image[row][column] for row in range(len(image)))
                for column in range(len(image[0]) - 1, -1, -1))

def rotate_right(image):
    return list(list(image[row][column]
                    for row in range(len(image) - 1, -1, -1))
                for column in range(len(image[0])))

def invert(image):
    return list(list(tuple(255 - image[row][column][i] for i in range(3))
                    for column in range(len(image[0])))
                for row in range(len(image)))

def lighten(image, num):
    return list(list(tuple(image[row][column][i] +
                int(num * (255 - image[row][column][i])) for i in range(3))
                    for column in range(len(image[0])))
                for row in range(len(image)))

def darken(image, num):
    return list(list(tuple(image[row][column][i] -
                int(num * (image[row][column][i] - 0)) for i in range(3))
                    for column in range(len(image[0])))
                for row in range(len(image)))

def list_of_lists(image):
    list_ = []
    list_copy = []
    result_list = []
    for col in range(3):
        for row in range(len(image)):
            for column in range(len(image[0])):
                for i in range(256):
                    if i == image[row][column][col]:
                        list_.append((i, 1))
        list_copy = list_
        result_list.append(list_copy)
        list_ = []
    return result_list

def list_to_dict(list_for_each_color):
    color = {}
    for num, repeats in list_for_each_color:
        if num in color:
            color[num] = color[num] + repeats
        else:
            color[num] = repeats
    return color

def list_of_dicts(list_of_lists):
    return list(list_to_dict(every_list) for every_list in list_of_lists)

def create_histogram(image):
    colors = ['red', 'green', 'blue']
    return dict(zip(colors, list_of_dicts(list_of_lists(image))))