def find_s(data): hypothesis = None for row in data: if row[-1] == "Yes": if hypothesis is None: hypothesis = row[:-1] else: hypothesis = ["?" if h != r else h for h, r in zip(hypothesis, row[:-1])] return hypothesis #"Sky", "Temp", "Humidity", "Wind", "Water", "Forecast", "EnjoySport" data = [ ["Sunny", "Warm", "Normal", "Strong", "Warm", "Same", "Yes"], ["Sunny", "Warm", "High", "Strong", "Warm", "Same", "Yes"], ["Rainy", "Cold", "High", "Strong", "Warm", "Change", "No"], ["Sunny", "Warm", "High", "Strong", "Cool", "Change", "Yes"] ] hypothesis = find_s(data) print("Most Specific Hypothesis:", hypothesis)