Finishing 11 new elements

This commit is contained in:
2020-01-08 17:32:09 +01:00
parent da0609f315
commit 1dcfd757e8
11 changed files with 411 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
def create_intervals(data):
"""
Create a list of intervals out of set of ints.
"""
results = []
data = sorted(data)
start = None
current_number = None
for number in data:
if start is None:
start = number
current_number = start
continue
if number != start and number != (current_number + 1):
results.append((start, current_number))
start = number
current_number = number
if start is not None:
results.append((start, current_number))
return iter(results)
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
res = create_intervals(iter(sorted(list({1, 2, 3, 4, 5, 7, 8, 12}))))
assert hasattr(res, '__iter__'), "your function should return the iterator object"
assert hasattr(res, '__next__'), "your function should return the iterator object"
assert list(create_intervals(iter(sorted(list({1, 2, 3, 4, 5, 7, 8, 12}))))) == [
(1, 5), (7, 8), (12, 12)], "First"
assert list(create_intervals(iter(sorted(list({1, 2, 3, 6, 7, 8, 4, 5}))))) == [
(1, 8)], "Second"
assert list(create_intervals(iter([]))) == [], "Empty"
print('Almost done! The only thing left to do is to Check it!')

View File

@@ -0,0 +1,25 @@
def flat_list(array):
return iter(flat_iter(array))
def flat_iter(array):
new_array = []
for i in array:
if hasattr(i, '__next__'):
new_array += flat_iter(i)
else:
new_array.append(i)
return new_array
if __name__ == '__main__':
res = flat_list([1, 2, 3])
assert hasattr(res, '__iter__'), "your function should return the iterator object"
assert hasattr(res, '__next__'), "your function should return the iterator object"
assert list(flat_list(iter([1, 2, 3]))) == [1, 2, 3], "First"
assert list(flat_list(iter([1, iter([2, 2, 2]), 4]))) == [1, 2, 2, 2, 4], "Second"
assert list(flat_list(iter([iter([2]), iter([4, iter([5, 6, iter([6]), 6, 6, 6]), 7])]))) == [2, 4, 5, 6, 6, 6, 6,
6, 7], "Third"
assert list(flat_list(iter([-1, iter([1, iter([-2]), 1]), -1]))) == [-1, 1, -2, 1, -1], "Four"
print('Done! Check it')

View File

@@ -0,0 +1,27 @@
def most_wanted(text: str) -> str:
text = text.lower()
letters = []
max = 0
for letter in text:
if letter.isalpha():
if letter not in letters:
count = text.count(letter)
if max == count:
letters.append(letter)
if count > max:
letters = [letter]
max = count
return letters
if __name__ == '__main__':
# These "asserts" using only for self-checking and not necessary for auto-testing
assert sorted(most_wanted("Hello World!")) == ["l"], "Hello test"
assert sorted(most_wanted("How do you do?")) == ["o"], "O is most wanted"
assert sorted(most_wanted("One")) == ["e", "n", "o"], "All letter only once."
assert sorted(most_wanted("Oops!")) == ["o"], "Don't forget about lower case."
assert sorted(most_wanted("AAaooo!!!!")) == ["a", "o"], "Only letters."
assert sorted(most_wanted("abe")) == ["a", "b", "e"], "The First."
print("Start the long test")
assert sorted(most_wanted("a" * 9000 + "b" * 1000)) == ["a"], "Long."
print("The local tests are done.")