Traceback (most recent call last):
File "tests.py", line 38, in <module>
test.assert_equals(dirReduc(a), ['NORTH', 'NORTH'])
File "/workspace/default/solution.py", line 6, in dirReduc
if {S[i], S[i - 1]} ==pair1 or {S[i], S[i - 1]} ==pair2:
IndexError: list index out of range
In this kata you are required to, given a string, replace every letter with its position in the alphabet.
If anything in the text isn't a letter, ignore it and don't return it.
"a" = 1, "b" = 2, etc.
Example
alphabet_position("The sunset sets at twelve o' clock.")
Should return "20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" (as a string)
alphabet = 'abcdefghijklmnopqrstuvwxyz'
def unpack(arg):
d = {}
for index, item in enumerate(arg):
d[item] = d.get(item, index) + 1
return d
alphabet_unpacked = unpack(alphabet)
def alphabet_position(text):
text_lowercase = text.lower()
result = ''
i = 0
while i < len(text_lowercase):
if text_lowercase[i] not in alphabet:
i += 1
continue
result += ' ' + str( + alphabet_unpacked.get(text_lowercase[i]))
i += 1
return result[1:]
def find_second_index(value, items):
if find_index(value, items):
return next(iter(items))
return None
const makeItFunny = (str, n) => {
let i = 0;
let result = '';
while (i < str.length) {
const current = str[i];
if ((i + 1) % n === 0) {
result += current.toUpperCase();
} else {
result += current;
}
i += 1;
}
return result;
};