### Vaccinations for children under 5
You have been put in charge of administrating vaccinations for children in your local area. Write a function that will generate a list of vaccines for each child presented for vaccination, based on the child's age and vaccination history, and the month of the year.
#### The function takes three parameters: age, status and month
- The parameter 'age' will be given in weeks up to 16 weeks, and thereafter in months. You can assume that children presented will be scheduled for vaccination (eg '16 weeks', '12 months' etc).
- The parameter 'status' indicates if the child has missed a scheduled vaccination, and the argument will be a string that says 'up-to-date', or a scheduled stage (eg '8 weeks') that has been missed, in which case you need to add any missing shots to the list. Only one missed vaccination stage will be passed in per function call.
- If the month is 'september', 'october' or 'november' add 'offer fluVaccine' to the list.
- Make sure there are no duplicates in the returned list, and sort it alphabetically.

#### Example input and output
~~~~
input     ('12 weeks', 'up-to-date', 'december')
output    ['fiveInOne', 'rotavirus']

input     ('12 months', '16 weeks', 'june')
output     ['fiveInOne', 'hibMenC', 'measlesMumpsRubella', 'meningitisB', 'pneumococcal']

input     ('40 months', '12 months', 'october') 
output    ['hibMenC', 'measlesMumpsRubella', 'meningitisB', 'offer fluVaccine', 'preSchoolBooster']
~~~~

#### To save you typing it up, here is the vaccinations list
~~~~
fiveInOne : ['8 weeks', '12 weeks', '16 weeks'],
//Protects against: diphtheria, tetanus, whooping cough, polio and Hib (Haemophilus influenzae type b)
pneumococcal : ['8 weeks', '16 weeks'],
//Protects against: some types of pneumococcal infection
rotavirus : ['8 weeks', '12 weeks'],
//Protects against: rotavirus infection, a common cause of childhood diarrhoea and sickness
meningitisB : ['8 weeks', '16 weeks', '12 months'],
//Protects against: meningitis caused by meningococcal type B bacteria
hibMenC : ['12 months'],
//Protects against: Haemophilus influenzae type b (Hib), meningitis caused by meningococcal group C bacteria    
measlesMumpsRubella : ['12 months', '40 months'],
//Protects against: measles, mumps and rubella
fluVaccine : ['september','october','november'],
//Given at: annually in Sept/Oct
preSchoolBooster : ['40 months']
//Protects against: diphtheria, tetanus, whooping cough and polio
~~~~

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Sorting

Data structures

Starter code: def vaccine_list(age, status, month):
	

Solutions:
from itertools import chain
TOME = {'8 weeks': ['fiveInOne', 'pneumococcal', 'rotavirus', 'meningitisB'], '12 weeks': ['fiveInOne', 'rotavirus'], '16 weeks': ['fiveInOne', 'pneumococcal', 'meningitisB'], '12 months': ['meningitisB', 'hibMenC', 'measlesMumpsRubella'], '40 months': ['measlesMumpsRubella', 'preSchoolBooster'], 'september': ['offer fluVaccine'], 'october': ['offer fluVaccine'], 'november': ['offer fluVaccine']}

def vaccine_list(*args):
	return sorted(set(chain.from_iterable((TOME.get(s, ()) for s in args))))


d = {'fiveInOne': ('8 weeks', '12 weeks', '16 weeks'), 'pneumococcal': ('8 weeks', '16 weeks'), 'rotavirus': ('8 weeks', '12 weeks'), 'meningitisB': ('8 weeks', '16 weeks', '12 months'), 'hibMenC': ('12 months',), 'measlesMumpsRubella': ('12 months', '40 months'), 'offer fluVaccine': ('september', 'october', 'november'), 'preSchoolBooster': ('40 months',)}
vaccine_list = lambda *args: sorted({k for i in args for (k, l) in d.items() if i in l if i != 'up-to-date'})


def vaccine_list(age, status, month):
	vaccines = {'8 weeks': {'fiveInOne', 'pneumococcal', 'rotavirus', 'meningitisB'}, '12 weeks': {'fiveInOne', 'rotavirus'}, '16 weeks': {'fiveInOne', 'pneumococcal', 'meningitisB'}, '12 months': {'meningitisB', 'hibMenC', 'measlesMumpsRubella'}, '40 months': {'measlesMumpsRubella', 'preSchoolBooster'}, 'up-to-date': set(), 'september': {'offer fluVaccine'}, 'october': {'offer fluVaccine'}, 'november': {'offer fluVaccine'}}
	return sorted(vaccines[age] | vaccines[status] | vaccines.get(month, set()))


VACCINATIONS = {'fiveInOne': ['8 weeks', '12 weeks', '16 weeks'], 'pneumococcal': ['8 weeks', '16 weeks'], 'rotavirus': ['8 weeks', '12 weeks'], 'meningitisB': ['8 weeks', '16 weeks', '12 months'], 'hibMenC': ['12 months'], 'measlesMumpsRubella': ['12 months', '40 months'], 'preSchoolBooster': ['40 months']}

def vaccine_list(age, status, month):
	return sorted(({'offer fluVaccine'} if month in ['september', 'october', 'november'] else set()) | {v for (v, times) in VACCINATIONS.items() if age in times or (status != 'up-to-date' and status in times)})


vaccinations = {'8 weeks': {'fiveInOne', 'pneumococcal', 'rotavirus', 'meningitisB'}, '12 weeks': {'fiveInOne', 'rotavirus'}, '16 weeks': {'fiveInOne', 'pneumococcal', 'meningitisB'}, '12 months': {'meningitisB', 'hibMenC', 'measlesMumpsRubella'}, '40 months': {'measlesMumpsRubella', 'preSchoolBooster'}, 'september': {'offer fluVaccine'}, 'october': {'offer fluVaccine'}, 'november': {'offer fluVaccine'}}

def vaccine_list(age, status, month):
	return sorted(vaccinations[age] | vaccinations.get(status, set()) | vaccinations.get(month, set()))


def vaccine_list(age, status, month):
	vaccine = {'fiveInOne': ['8 weeks', '12 weeks', '16 weeks'], 'pneumococcal': ['8 weeks', '16 weeks'], 'rotavirus': ['8 weeks', '12 weeks'], 'meningitisB': ['8 weeks', '16 weeks', '12 months'], 'hibMenC': ['12 months'], 'measlesMumpsRubella': ['12 months', '40 months'], 'fluVaccine': ['september', 'october', 'november'], 'preSchoolBooster': ['40 months']}
	req = []
	for jab in vaccine:
		if status in vaccine[jab]:
			req.append(jab)
		if age in vaccine[jab] and jab not in req:
			req.append(jab)
	if month in vaccine['fluVaccine']:
		req.append('offer fluVaccine')
	req.sort()
	return req


vaccines = {'8 weeks': ['fiveInOne', 'pneumococcal', 'rotavirus', 'meningitisB'], '12 weeks': ['fiveInOne', 'rotavirus'], '16 weeks': ['fiveInOne', 'pneumococcal', 'meningitisB'], '12 months': ['meningitisB', 'measlesMumpsRubella', 'hibMenC'], '40 months': ['measlesMumpsRubella', 'preSchoolBooster'], 'september': ['offer fluVaccine'], 'october': ['offer fluVaccine'], 'november': ['offer fluVaccine']}

def vaccine_list(age, status, month):
	lists_of_vaccines = [vaccines[v] for v in [age, status, month] if v in vaccines]
	return sorted(list(set([v for lst in lists_of_vaccines for v in lst])))


from itertools import chain

def vaccine_list(age, status, month):
	flu_months = ['september', 'october', 'november']
	vac_sched = {'8 weeks': ['fiveInOne', 'pneumococcal', 'rotavirus', 'meningitisB'], '12 weeks': ['fiveInOne', 'rotavirus'], '16 weeks': ['fiveInOne', 'pneumococcal', 'meningitisB'], '12 months': ['meningitisB', 'hibMenC', 'measlesMumpsRubella'], '40 months': ['measlesMumpsRubella', 'preSchoolBooster']}
	if status == 'up-to-date':
		status = age
	vac_time = list(vac_sched.keys())
	vacs_toDo = [v for (k, v) in vac_sched.items() if k in [status, age]]
	vac_list = list(set(list(chain.from_iterable(vacs_toDo))))
	if month in flu_months:
		vac_list.append('offer fluVaccine')
	return sorted(vac_list)


def vaccine_list(age, status, month):
	dict = {'fiveInOne': ['8 weeks', '12 weeks', '16 weeks'], 'pneumococcal': ['8 weeks', '16 weeks'], 'rotavirus': ['8 weeks', '12 weeks'], 'meningitisB': ['8 weeks', '16 weeks', '12 months'], 'hibMenC': ['12 months'], 'measlesMumpsRubella': ['12 months', '40 months'], 'fluVaccine': ['september', 'october', 'november'], 'preSchoolBooster': ['40 months']}
	vac_list = []
	for key in dict:
		if age in dict[key] or status in dict[key]:
			vac_list.append(key)
	if month in dict['fluVaccine']:
		vac_list.append('offer fluVaccine')
	return sorted(vac_list)