|
1
|
|
|
def CipherText(text): |
|
2
|
|
|
return ''.join([j.lower() for i in text for j in i if j != ' ']).split('\n') |
|
3
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
def checkio(text, word): |
|
6
|
|
|
CipheredText = CipherText(text) |
|
7
|
|
|
LongestLine = max(map(len, CipheredText)) |
|
8
|
|
|
for i in range(len(CipheredText)): |
|
9
|
|
|
CipheredText[i] += ' ' * (LongestLine - len(CipheredText[i])) |
|
10
|
|
|
RowStart, RowEnd, ColStart, ColEnd = 0, 0, 0, 0 |
|
11
|
|
|
# in rows |
|
12
|
|
|
for i, j in enumerate(CipheredText): |
|
13
|
|
|
index = j.find(word) |
|
14
|
|
|
if index != -1: |
|
15
|
|
|
RowStart = RowEnd = i + 1 |
|
16
|
|
|
ColStart = index + 1 |
|
17
|
|
|
ColEnd = index + len(word) |
|
18
|
|
|
if RowStart != 0: |
|
19
|
|
|
return [RowStart, ColStart, RowEnd, ColEnd] |
|
20
|
|
|
# in cols |
|
21
|
|
|
CipheredText = list(zip(*CipheredText[::])) |
|
22
|
|
|
for i in range(len(CipheredText)): |
|
23
|
|
|
CipheredText[i] = ''.join(list(CipheredText[i])) |
|
24
|
|
|
for i, j in enumerate(CipheredText): |
|
25
|
|
|
index = j.find(word) |
|
26
|
|
|
if index != -1: |
|
27
|
|
|
ColStart = ColEnd = i + 1 |
|
28
|
|
|
RowStart = index + 1 |
|
29
|
|
|
RowEnd = index + len(word) |
|
30
|
|
|
return [RowStart, ColStart, RowEnd, ColEnd] |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
# These "asserts" using only for self-checking and not necessary for |
|
34
|
|
|
# auto-testing |
|
35
|
|
View Code Duplication |
if __name__ == '__main__': |
|
|
|
|
|
|
36
|
|
|
assert ( |
|
37
|
|
|
checkio( |
|
38
|
|
|
u"""DREAMING of apples on a wall, |
|
39
|
|
|
And dreaming often, dear, |
|
40
|
|
|
I dreamed that, if I counted all, |
|
41
|
|
|
-How many would appear?""", |
|
42
|
|
|
u"ten", |
|
43
|
|
|
) |
|
44
|
|
|
== [2, 14, 2, 16] |
|
45
|
|
|
) |
|
46
|
|
|
assert ( |
|
47
|
|
|
checkio( |
|
48
|
|
|
u"""He took his vorpal sword in hand: |
|
49
|
|
|
Long time the manxome foe he sought-- |
|
50
|
|
|
So rested he by the Tumtum tree, |
|
51
|
|
|
And stood awhile in thought. |
|
52
|
|
|
And as in uffish thought he stood, |
|
53
|
|
|
The Jabberwock, with eyes of flame, |
|
54
|
|
|
Came whiffling through the tulgey wood, |
|
55
|
|
|
And burbled as it came!""", |
|
56
|
|
|
u"noir", |
|
57
|
|
|
) |
|
58
|
|
|
== [4, 16, 7, 16] |
|
59
|
|
|
) |
|
60
|
|
|
|