For every good kata idea there seem to be quite a few bad ones!

In this kata you need to check the provided 2 dimensional array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, return 'Fail!'.

The sub arrays may not be the same length.

The solution should be case insensitive (ie good, GOOD and gOOd all count as a good idea). All inputs may not be strings.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: def well(arr):
	

Solutions:
from itertools import chain

def well(arr):
	c = sum((isinstance(x, str) and x.lower() == 'good' for x in chain.from_iterable(arr)))
	return 'I smell a series!' if c > 2 else 'Publish!' if c > 0 else 'Fail!'


def well(arr):
	good_ideas = str(arr).lower().count('good')
	return 'I smell a series!' if good_ideas > 2 else 'Fail!' if not good_ideas else 'Publish!'


def well(arr):
	nb_good = sum((1 for lst in arr for word in lst if str(word).lower() == 'good'))
	return 'I smell a series!' if nb_good > 2 else 'Publish!' if nb_good > 0 else 'Fail!'


from itertools import chain
from typing import List, Any

def well(arr: List[List[Any]]) -> str:
	good = (a for a in chain(*arr) if isinstance(a, str) and a.lower() == 'good')
	if next(good, False):
		if next(good, False) and next(good, False):
			return 'I smell a series!'
		return 'Publish!'
	return 'Fail!'


def well(arr):
	total = 0
	for i in arr:
		for j in i:
			if isinstance(j, str) and j.lower() == 'good':
				total += 1
	return 'Fail!' if total == 0 else 'I smell a series!' if total > 2 else 'Publish!'


def well(arr):
	bad1 = 0
	good = 0
	for i in arr:
		for j in i:
			if str(j).lower() == 'bad':
				bad1 += 1
			if str(j).lower() == 'good':
				good += 1
	if 0 < good < 3:
		return 'Publish!'
	if good > 2:
		return 'I smell a series!'
	if good == 0:
		return 'Fail!'


well = lambda a, f=__import__('itertools').chain.from_iterable: {0: 'Fail!', 1: 'Publish!', 2: 'Publish!'}.get(sum((str(w).lower() == 'good' for w in f(a))), 'I smell a series!')


def well(arr):
	c = ''.join(map(str, arr)).lower().count('good')
	return ['Fail!', 'Publish!', 'I smell a series!'][bool(c) + (c > 2)]


def well(arr):
	c = len([j for i in arr for j in i if str(j)[0] in 'Gg'])
	if c == 0:
		return 'Fail!'
	elif c <= 2:
		return 'Publish!'
	else:
		return 'I smell a series!'


def well(arr):
	s = []
	for x in arr:
		s += x
	a = []
	for c in s:
		if isinstance(c, str):
			a.append(c)
	cpt = 0
	for w in a:
		if w.lower() == 'good':
			cpt += 1
	if cpt > 2:
		return 'I smell a series!'
	if 0 < cpt < 3:
		return 'Publish!'
	return 'Fail!'