To celebrate today's launch of my Hero's new book: Alan Partridge: Nomad, We have a new series of kata arranged around the great man himself.

Given an array of terms, if any of those terms relate to Alan Partridge, return Mine's a Pint!

The number of ! after the t should be determined by the number of Alan related terms you find in the provided array (x). The related terms are:

Partridge
PearTree
Chat
Dan
Toblerone
Lynn
AlphaPapa
Nomad

If you don't find any related terms, return 'Lynn, I've pierced my foot on a spike!!'

All Hail King Partridge

Other katas in this series:
Alan Partridge II - Apple Turnover
Alan Partridge III - London

Difficulty: introductory

Starter code:

def part(arr):
	

Solutions:
def part(arr):
    l = ["Partridge", "PearTree", "Chat", "Dan", "Toblerone", "Lynn", "AlphaPapa", "Nomad"]
    s = len([i for i in arr if i in l])
    return "Mine's a Pint"+"!"*s if s>0 else 'Lynn, I\'ve pierced my foot on a spike!!'

def part(arr):
    terms = {'Partridge', 'PearTree', 'Chat', 'Dan', 'Toblerone', 'Lynn', 'AlphaPapa', 'Nomad'}
    marks = ''.join('!' for x in arr if x in terms)
    return "Mine's a Pint" + marks if marks else "Lynn, I've pierced my foot on a spike!!"

def part(arr):
  terms = frozenset(['Partridge', 'PearTree', 'Chat', 'Dan', 'Toblerone', 'Lynn', 'AlphaPapa', 'Nomad'])
  
  count = sum(1 for x in arr if x in terms)
  
  return "Mine's a Pint" + "!" * count if count > 0 else "Lynn, I've pierced my foot on a spike!!"

check = {"Partridge", "PearTree", "Chat", "Dan", "Toblerone", "Lynn", "AlphaPapa", "Nomad"}.__contains__

def part(arr):
    result = sum(map(check, arr))
    return f"Mine's a Pint{'!'*result}" if result else "Lynn, I've pierced my foot on a spike!!"

from collections import Counter

def part(arr):
    c =  Counter([i in {'Partridge','PearTree','Chat','Dan','Toblerone','Lynn','AlphaPapa','Nomad'} for i in arr])
    return "Mine's a Pint" + c[True] * '!' if True in c else "Lynn, I've pierced my foot on a spike!!" 


related = {"Partridge", "PearTree", "Chat", "Dan", "Toblerone", "Lynn", "AlphaPapa", "Nomad"}

def part(arr):
    found = sum(1 for w in arr if w in related)
    return f"Mine's a Pint{'!' * found}" if found else "Lynn, I've pierced my foot on a spike!!"

def part(a):
    s = {"Partridge", "PearTree", "Chat", "Dan", "Toblerone", "Lynn", "AlphaPapa", "Nomad"}
    n = sum(x in s for x in a)
    return "Mine's a Pint{}".format("!" * n) if n else "Lynn, I've pierced my foot on a spike!!"

def part(arr):
    terms = ["Partridge","PearTree","Chat","Dan","Toblerone","Lynn","AlphaPapa","Nomad"]
    x = (sum(1 for i in arr if i in terms))
    return "Mine's a Pint{}".format("!"*x) if x>0 else "Lynn, I've pierced my foot on a spike!!"

S = {"Partridge", "PearTree", "Chat", "Dan", "Toblerone", "Lynn", "AlphaPapa", "Nomad"}
def part(arr):
    n = sum(w in S for w in arr)
    return "Lynn, I've pierced my foot on a spike!!" if not n else "Mine's a Pint"+"!"*n

def part(arr):
    st = frozenset(('Partridge', 'PearTree', 'Chat', 'Dan', 'Toblerone', 'Lynn', 'AlphaPapa', 'Nomad'))
    s = sum(x in st for x in arr)
    return "Mine's a Pint" + '!' * s if s else "Lynn, I've pierced my foot on a spike!!"