|
@@ -63,19 +63,37 @@ def get_first_repeated_word(words: List[str]) -> Optional[str]:
|
|
|
return None
|
|
|
|
|
|
|
|
|
- # for w in words:
|
|
|
- # if words.count(w) > 1:
|
|
|
- # return w
|
|
|
- # return None
|
|
|
-
|
|
|
+def rotate(lst: list[int | float], shift: int = 1) -> list[int | float] :
|
|
|
+ 'Функция выполняет циклический сдвиг списка на shift позиций вправо(shift>0) или влево(shift<0)'
|
|
|
+ shifted_list = []
|
|
|
+
|
|
|
+ if shift > len(lst):
|
|
|
+ foo = shift%len(lst)
|
|
|
+ if shift < 0:
|
|
|
+ foo = - foo - 1
|
|
|
+ else:
|
|
|
+ foo = shift
|
|
|
+
|
|
|
+ if shift < 0:
|
|
|
+ shifted_list.extend(lst[-foo:])
|
|
|
+ shifted_list.extend(lst[:-foo])
|
|
|
+ elif shift > 0:
|
|
|
+ shifted_list.extend(lst[-foo:])
|
|
|
+ shifted_list.extend(lst[:-foo])
|
|
|
+ return shifted_list
|
|
|
|
|
|
|
|
|
def main():
|
|
|
# print(get_even.__doc__)
|
|
|
- print(get_first_repeated_word.__doc__)
|
|
|
- print(get_first_repeated_word.__annotations__)
|
|
|
- print(get_first_repeated_word(['ab', 'ca', 'bc', 'ca', 'ab', 'bc']))
|
|
|
+ # print(get_first_repeated_word.__doc__)
|
|
|
+ # print(get_first_repeated_word.__annotations__)
|
|
|
+ # print(get_first_repeated_word(['ab', 'ca', 'bc', 'ca', 'ab', 'bc']))
|
|
|
+
|
|
|
|
|
|
+ print(rotate([1, 2, 3, 4, 5, 6], 2))
|
|
|
+ print(rotate([1, 2, 3, 4, 5, 6], -10))
|
|
|
+ print(rotate([1, 2, 3, 4, 5, 6, 7], 21))
|
|
|
+ print(rotate([1, 2, 3, 4, 5, 6], -3))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
main()
|