Advertisement
fkudinov

7. Most Wanted Letter / Вирішуємо задачі на Python CheckIO Українською

Sep 1st, 2023
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | Source Code | 0 0
  1. #   ----------     tasks/most_wanted.py   ---------------
  2.  
  3. LETTERS = "abcdefghijklmnopqrstuvwxyz"
  4.  
  5.  
  6. def checkio(text: str) -> str:
  7.  
  8.     text = text.lower()
  9.  
  10.     item = "a"
  11.     val = text.count(item)
  12.  
  13.     for _item in LETTERS:
  14.         _val = text.count(_item)
  15.  
  16.         if val < _val:
  17.             item = _item
  18.             val = _val
  19.  
  20.     return item
  21.  
  22.  
  23. def checkio_max(text: str) -> str:
  24.     return max(LETTERS, key=text.lower().count)
  25.  
  26.  
  27. # --------    tests/test_most_wanted.py   ----------------
  28.  
  29. import pytest
  30.  
  31. from tasks.most_wanted import checkio, checkio_max
  32.  
  33.  
  34. @pytest.mark.parametrize("func", [checkio, checkio_max])
  35. @pytest.mark.parametrize(["text", "res"], [
  36.     ["Hello World!", "l"],
  37.     ["How do you do?", "o"],
  38.     ["One", "e"],
  39.     ["Oops!", "o"],
  40.     ["AAaooo!!!!", "a"],
  41.     ["abe", "a"],
  42.     ["a" * 9000 + "b" * 1000, "a"],
  43.     ["oooAAa!!!!", "a"],
  44. ])
  45. def test_most_wanted(func, text, res):
  46.     assert func(text) == res
  47.  
  48.  
  49.  
  50.  
Tags: checkio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement