Ответ:
#Python 3.8.3
from typing import *
def FindFirstIndex(source: Iterable[Any], predicate: Callable[[Any], Any]):
for index, item in enumerate(source):
if (predicate(item)):
return index
def main():
arr = [1, 2, 3, 4, 5, -1, 2, -4]
firstOdd = FindFirstIndex(arr, lambda p: p % 2 != 0)
firstNegative = FindFirstIndex(arr, lambda p: p < 0)
arr[firstOdd], arr[firstNegative] = arr[firstNegative], arr[firstOdd]
print(arr)
if __name__ == '__main__':
main()
Объяснение:
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
#Python 3.8.3
from typing import *
def FindFirstIndex(source: Iterable[Any], predicate: Callable[[Any], Any]):
for index, item in enumerate(source):
if (predicate(item)):
return index
def main():
arr = [1, 2, 3, 4, 5, -1, 2, -4]
firstOdd = FindFirstIndex(arr, lambda p: p % 2 != 0)
firstNegative = FindFirstIndex(arr, lambda p: p < 0)
arr[firstOdd], arr[firstNegative] = arr[firstNegative], arr[firstOdd]
print(arr)
if __name__ == '__main__':
main()
Объяснение: