aboutsummaryrefslogtreecommitdiff
path: root/challenge-256/sgreen/python/ch-1.py
blob: e84c83e639a64ba06e45af163a00c4e083604db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3

import sys


def count_pairs(words: list) -> int:
    """Count the number of pairs of strings where one is reversed

    Args:
        words (list): A list of words

    Returns:
        int: The number of pairs
    """
    count = 0

    while words:
        # Take one word from the list
        word = words.pop()

        # See if the reverse of it is also in the list
        if word[::-1] in words:
            count += 1

    # Return the number of pairs
    return count


def main():
    result = count_pairs(sys.argv[1:])
    print(result)


if __name__ == '__main__':
    main()