diff options
Diffstat (limited to 'challenge-256/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-256/sgreen/python/ch-1.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-256/sgreen/python/ch-1.py b/challenge-256/sgreen/python/ch-1.py new file mode 100755 index 0000000000..e84c83e639 --- /dev/null +++ b/challenge-256/sgreen/python/ch-1.py @@ -0,0 +1,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() |
