From c99fccc47d011268d47c3224a1d3097eb4f588f8 Mon Sep 17 00:00:00 2001 From: Yuliya-Nad Date: Mon, 23 Dec 2019 20:12:45 +0200 Subject: [PATCH] ready for codereview --- nadya/first/task1.py | 10 ++++++++++ nadya/first/task2.py | 10 ++++++++++ nadya/first/task3.py | 9 +++++++++ nadya/second/__init__.py | 0 nadya/second/task1.py | 26 ++++++++++++++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 nadya/first/task1.py create mode 100644 nadya/first/task2.py create mode 100644 nadya/first/task3.py create mode 100644 nadya/second/__init__.py create mode 100644 nadya/second/task1.py diff --git a/nadya/first/task1.py b/nadya/first/task1.py new file mode 100644 index 0000000..14d8312 --- /dev/null +++ b/nadya/first/task1.py @@ -0,0 +1,10 @@ +""" +задан список з різними типами даних +вивести кількість елементів типу float +""" +newlist=["k",6.8,99,345,True,"66"] +count=0 +for i in newlist: + if isinstance(i,float): + count=count+1 +print(count) \ No newline at end of file diff --git a/nadya/first/task2.py b/nadya/first/task2.py new file mode 100644 index 0000000..197a4a5 --- /dev/null +++ b/nadya/first/task2.py @@ -0,0 +1,10 @@ +""" +задан рядок +вивести кількість чисел у рядку +""" +text="ghkdlh5673bjhdvfl" +count=0 +for i in text: + if i.isdigit(): + count=count+1 +print(count) \ No newline at end of file diff --git a/nadya/first/task3.py b/nadya/first/task3.py new file mode 100644 index 0000000..9c9c03c --- /dev/null +++ b/nadya/first/task3.py @@ -0,0 +1,9 @@ +""" +дано рядок тексту +вивести кожне друге слово з кінця +""" +text="Just always and always look around and act wisely" +newlist=list(text.split(" ")) +rang=len(newlist) +for i in range(rang-2, -1, -2): + print(newlist[i]) \ No newline at end of file diff --git a/nadya/second/__init__.py b/nadya/second/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nadya/second/task1.py b/nadya/second/task1.py new file mode 100644 index 0000000..ba78f63 --- /dev/null +++ b/nadya/second/task1.py @@ -0,0 +1,26 @@ +""" +Заданий рядок тексту. +Вивести список, що складається с елементів-списків, де перший елемент-кожне друге слово, в другий- кількість його повторів у реченні +""" +import re +lis=[] +amount_list=[] +fin_list=[] +text="HI there, i have double-cheese in my bag" + +def find_most_frequent(text): + new_text=re.findall("\w+", text) + print(new_text) + for elem in new_text: + for i in range(len(new_text)-1):#range 0-8 + if i%2==1: + lis.append(elem) + print(lis) + for i in range(len(lis)-1): + amount=re.findall(lis[i], text) + amount_list.append(len(amount)) + print(amount_list, lis) + for i in range(len(lis)-1): + fin_list.append([lis[i], amount[i]]) + print(fin_list) +find_most_frequent(text)