diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2023-05-01 10:54:22 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2023-05-01 10:54:22 +0200 |
| commit | e91360307f1b27e544ac7108aa5ea49e7b30b58d (patch) | |
| tree | fee210be1e7fc78409e1d82a951c9b0cdea48d16 /challenge-215/lubos-kolouch/python/ch-1.py | |
| parent | cd1cf9c3a97571dca788b4e1a0c5ce74c05927ef (diff) | |
| download | perlweeklychallenge-club-e91360307f1b27e544ac7108aa5ea49e7b30b58d.tar.gz perlweeklychallenge-club-e91360307f1b27e544ac7108aa5ea49e7b30b58d.tar.bz2 perlweeklychallenge-club-e91360307f1b27e544ac7108aa5ea49e7b30b58d.zip | |
Challenge 215 LK Perl Python
Diffstat (limited to 'challenge-215/lubos-kolouch/python/ch-1.py')
| -rw-r--r-- | challenge-215/lubos-kolouch/python/ch-1.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/challenge-215/lubos-kolouch/python/ch-1.py b/challenge-215/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..d5282fb7fa --- /dev/null +++ b/challenge-215/lubos-kolouch/python/ch-1.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + + +def count_unsorted_words(words): + count = 0 + + for word in words: + count += is_unsorted(word) + + return count + + +def is_unsorted(word): + previous_char = word[0] + + for i in range(1, len(word)): + current_char = word[i] + if current_char < previous_char: + return 1 + previous_char = current_char + + return 0 + + +# Test cases +words1 = ["abc", "xyz", "tsu"] +words2 = ["rat", "cab", "dad"] +words3 = ["x", "y", "z"] + +print(count_unsorted_words(words1)) # Output: 1 +print(count_unsorted_words(words2)) # Output: 3 +print(count_unsorted_words(words3)) # Output: 0 |
