add counter task
This commit is contained in:
parent
64a3f5ae28
commit
9eed7cb032
@ -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)
|
||||
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
```
|
19
practica/stepik/stepik_tasks/peace_and_war.py
Normal file
19
practica/stepik/stepik_tasks/peace_and_war.py
Normal file
@ -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')
|
Loading…
Reference in New Issue
Block a user