32
Vladimir
Last seen 1 day ago
Member for 4 years, 1 month, 9 days
Difficulty Normal
One line of code is superfluous.
You should change variable names :)
def sort_by_removing(values: list) -> list:
copy = []
for n in values:
if not copy: copy.append(n)
elif n >= copy[-1]: copy.append(n)
return copy
More
It is enough to write
return len(p) > 6
because it returns boolean.
More
The condition is redundant because a slice doesn't raise an IndexError. E.g.:
print([][2:]) # output: []
More
The code in lines 3 and 5 can be deleted by replacing line 7 with
if not i.isspace() and i != '':
More
it would be too long to iterate through all the list if it contained hundreds of equal elements. slicing would be faster :)
More
It is superfluous:
if len(elements) <2:
return True
because
len(set(elements))<=1
returns True for empty list
More
maybe it would be better use 'elif' clause so as not to go through all the directions
More
It could be shorter:
list({word: 0 for word in text.split() if word in words}) == words
More
It can be written without list conversion, because a set is an iterator:
lst = sorted(words_set, key = lambda i:len(i))
And the first condition is unnecessary.
More