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

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

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

Резултати

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

Код

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 (преди над 5 години)

+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 (преди над 5 години)

def rotate_left(image):
- return list(list(image[row][column] for row in range(len(image[0])))
+ 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[0]) - 1, -1, -1))
+ 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[0])))
+ 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[0])))
+ 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[0])))
+ 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[0])):
+ 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 (преди над 5 години)

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))
+ 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])))
+ 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)))
+ 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)))
+ 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)))
+ 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))))