Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
The operator module solution in Creative category for Safe Coasts by EnCuKou
"""Lesson 12: The operator module
Required reference re-reading: https://docs.python.org/3/library/operator.html
Today we will demonstrate the usage of Python's "operator" module in
a naval/supernatural application context.
The following functions will be covered:
* comparisons (eq, ne, le, ge, gt, lt)
* boolean logic (and_, or_, not_)
* arithmetic (add, sub, mul)
* getitem
* contains
* methodcaller
Pay close attention to the usage of methodcaller. It will be on the quiz.
"""
from operator import *
def finish_map(input_map):
def A(mo, P=methodcaller):
return [''.join(((mo[1] if getitem(mo, 0) in [getitem(M[-1], k)[l]
for k in range(sub(i, 1), add(i, 2))
for l in range(add(j, 1), sub(j, 2), -1)
if all([le(0, k), gt(len(getitem(M, -1)), k), ge(l, 0), lt(l, len(L))])
and P(eq(i, k), eq(j, l))] else c) if contains(c, '.') else c)
for j, c in enumerate(L)) for i, L in enumerate(getitem(M, -1))]
M = [input_map]
M.append(A('XS'))
next(mo for mo in (M.append(A('DD', or_))
for mo in range(mul(len(M[-1]), len(M[-1][0]))))
if not_(ne(*getitem(M, slice(-2, None)))))
return A('.S', and_)
Aug. 29, 2014
Comments: