# Alphabet Symmetry in Python

## The challenge

Consider the word `"abode"`. We can see that the letter `a` is in position `1` and `b` is in position `2`. In the alphabet, `a` and `b` are also in positions `1` and `2`. Notice also that `d` and `e` in `abode` occupy the positions they would occupy in the alphabet, which are positions `4` and `5`.

Given an array of words, return an array of the number of letters that occupy their positions in the alphabet for each word. For example,

`.wp-block-code{border:0;padding:0}.wp-block-code>div{overflow:auto}.shcb-language{border:0;clip:rect(1px,1px,1px,1px);-webkit-clip-path:inset(50%);clip-path:inset(50%);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;word-wrap:normal;word-break:normal}.hljs{box-sizing:border-box}.hljs.shcb-code-table{display:table;width:100%}.hljs.shcb-code-table>.shcb-loc{color:inherit;display:table-row;width:100%}.hljs.shcb-code-table .shcb-loc>span{display:table-cell}.wp-block-code code.hljs:not(.shcb-wrap-lines){white-space:pre}.wp-block-code code.hljs.shcb-wrap-lines{white-space:pre-wrap}.hljs.shcb-line-numbers{border-spacing:0;counter-reset:line}.hljs.shcb-line-numbers>.shcb-loc{counter-increment:line}.hljs.shcb-line-numbers .shcb-loc>span{padding-left:.75em}.hljs.shcb-line-numbers .shcb-loc::before{border-right:1px solid #ddd;content:counter(line);display:table-cell;padding:0 .75em;text-align:right;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;white-space:nowrap;width:1%}`solve(["abode","ABc","xyzD"]) = [4, 3, 1]`Code language: JavaScript (javascript)`

See test cases for more examples.

Input will consist of alphabet characters, both uppercase and lowercase. No spaces.

## The solution in Python code

Option 1:

``````from operator import eq
from string import ascii_lowercase

def solve(strings):
return [sum(map(eq, s.lower(), ascii_lowercase)) for s in strings]
```Code language: Python (python)```

Option 2:

``````def solve(arr):
return [sum(i == ord(c) - ord('A') for i, c in enumerate(s.upper())) for s in arr]
```Code language: Python (python)```

Option 3:

``````def solve(words):
return [sum(a==b for a, b in zip(w.lower(), 'abcdefghijklmnopqrstuvwxyz')) for w in words]
```Code language: Python (python)```

## Test cases to validate our solution

``````test.it("Basic tests")
test.assert_equals(solve(["abode","ABc","xyzD"]),[4,3,1])
test.assert_equals(solve(["abide","ABc","xyz"]),[4,3,0])
test.assert_equals(solve(["IAMDEFANDJKL","thedefgh","xyzDEFghijabc"]),[6,5,7])
test.assert_equals(solve(["encode","abc","xyzD","ABmD"]),[1, 3, 1, 3])
```Code language: Python (python)```
Tags:
Subscribe
Notify of