From 9eed7cb0325aab527df28fa9ff5e9d9a7057c898 Mon Sep 17 00:00:00 2001 From: Yesenya Date: Wed, 22 Nov 2023 23:41:21 +0300 Subject: [PATCH] add counter task --- practica/README.md | 1 + practica/stepik/README.md | 1 + practica/stepik/stepik_tasks/README.md | 11 +++++++++++ practica/stepik/stepik_tasks/peace_and_war.py | 19 +++++++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 practica/stepik/stepik_tasks/peace_and_war.py diff --git a/practica/README.md b/practica/README.md index 5e7aad5..b8cbf42 100644 --- a/practica/README.md +++ b/practica/README.md @@ -34,6 +34,7 @@ Among them there are: - [Sum of squared numbers](stepik/stepik_tasks/sum_of_squared_numbers.py) - [Tickets](stepik/stepik_tasks/tickets.py) - [Function of updating dictionary](stepik/stepik_tasks/update_dictionary.py) + - [Counter the same elements](stepik/stepik_tasks/peace_and_war.py) diff --git a/practica/stepik/README.md b/practica/stepik/README.md index 8bab473..3f53c47 100644 --- a/practica/stepik/README.md +++ b/practica/stepik/README.md @@ -29,5 +29,6 @@ different tasks from various courses - [sum_num_nearby](stepik_tasks/sum_num_nearby.py) - [Tickets](stepik_tasks/tickets.py) - [Function of updating dictionary](stepik_tasks/update_dictionary.py) +- [Counter the same elements](stepik_tasks/peace_and_war.py) \ No newline at end of file diff --git a/practica/stepik/stepik_tasks/README.md b/practica/stepik/stepik_tasks/README.md index bf297d5..9fc88a4 100644 --- a/practica/stepik/stepik_tasks/README.md +++ b/practica/stepik/stepik_tasks/README.md @@ -76,3 +76,14 @@ __*Plan of solution*__: update_dictionary(d, 1, -3) print(d) # {2: [-1, -2, -3]} ``` +- [Counter the same elements](peace_and_war.py) + + You input some words like: a aa abC aa ac abc bcd a (with diff redisters), then the program count the same elements and displays it in the dictionary. + ```python + Example output: + a 2 + aa 2 + abc 2 + ac 1 + bcd 1 + ``` \ No newline at end of file diff --git a/practica/stepik/stepik_tasks/peace_and_war.py b/practica/stepik/stepik_tasks/peace_and_war.py new file mode 100644 index 0000000..7a4fcfc --- /dev/null +++ b/practica/stepik/stepik_tasks/peace_and_war.py @@ -0,0 +1,19 @@ +text = input().lower().split() +list = {} +ind = 0 +len_t = len(text) +for word in text: + if ind != len_t: + if word in text: + n = text.count(word) + list[word] = (n) + ind+=1 +for key, items in list.items(): + print (key,items) + + + +# text = input().lower().split() +# d = { i : text.count(i) for i in text } +# for key, value in d.items(): +# print(key, value, end='\n') \ No newline at end of file