-
Notifications
You must be signed in to change notification settings - Fork 51
Ready for codereview #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
|
||
| import re | ||
|
|
||
| numb = str(input('Введіть номер автомобіля\n')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нема сенсу писати str(input()), бо input() і так повертає str
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Регулярний вираз виглядає не дуже,навіщо тут потрібен метод split.
Програма не працює. Це завдання можно виконати наступним чином:
import re
text = input("Введіть текст з форматом номера [АА 0000 BB]\n")
find = re.findall("[A-Z]{2}\s\d{4}\s[A-Z]{2}", text)
for i in find:
replace = i[3:8] + i[:2]
text = re.sub("[A-Z]{2}\s\d{4}\s[A-Z]{2}", replace, text)
print(text)
| #Вивести усі порожні списки з поданого списку | ||
|
|
||
|
|
||
| L= [ 1, 2, [], 21, 22, [],1223, [], 'hi'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Краще назвати змінну list, не записувати назву змінної в одну букву
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
L= [ 1, 2, [], 21, 22, [],1223, [], 'hi']
def count_empt_list(L):
return L.count([])
print(count_empt_list(L))
| text=input("Введіть рядок\n") | ||
| words=text.split(" ") | ||
| for word in words: | ||
| if(word[0].isupper()): | ||
| print(word) No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Можливо краще створити порожній список і додавати в нього елементи, які знаходяться у верхньому регістрі: result = []
string = input('Введіть рядок: ')
string= string.split(' ')
for i in string:
for j in i:
if(j.isupper()):
result.append(i)
break
print(result)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string = input()
def uppercase_letters(string):
result = []
for el in string.split():
if any(elem.isupper() for elem in el):
result.append(el)
return result
print(uppercase_letters(string))
| elif (type(L[i])) == str: | ||
| string = string + L[i] + '' | ||
| else: | ||
| print("Не працює\n",L[i]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Навіщо потрібен 12 рядок коду, у завданні незазначений цей пункт.
- Напевно краще виконати це завдання застосувавши функцію isinstance, вона створена спеціально для перевірки приналежності даних конкретному типу даних:
L = [1 ,22,35,76,'hi',[],22,'Bro']
sum = 0
string = ""
for value in L:
if isinstance(value, int):
sum = sum + value
elif isinstance(value, str):
string = string + ' ' + value
print("Сума чисел -",sum)
print("Об'єднання рядків -",string)
No description provided.