Используя функцию reduce, реализуйте код, который считает, сколько раз слово was встречается в списке:
sentences = “Nory was a Catholic”, “because her mother was a Catholic”, “and Nory’s mother was a Catholic”, “because her father was a Catholic”, “and her father was a Catholic”, “because his mother was a Catholic”, “or had been”
Моё решение не выдаёт ошибку:
from functools import reduce from typing import List def count(): return print(1) sentences = "Nory was a Catholic", "because her mother was a Catholic", "and Nory’s mother was a Catholic", "because her father was a Catholic", "and her father was a Catholic", "because his mother was a Catholic", "or had been" list1 = str(sentences) list1 = list1.split() char = 'was' count = 0 was = reduce(lambda x,y: x == 'was', filter(lambda y: y == 'was', sentences)) print(was)