def find_header_match(keys, candidates):
	for key in candidates:
		key = key.strip().lower()
		try:
			keys.remove(key)
		except ValueError:
			continue
		else:
			return key
	return None


class Table:
	#title = ''
	#header = []
	#rows = []
	#tabletype = 'Unknown'

	def __init__(self, t, cells):
		self.title = t
		self.header = list(cells.pop(0))
		self.rows = list(cells)
		self.tabletype = 'Unknown'
		self.identify()

	def identify(self):
		keys = [h.strip().lower() for h in self.header]
		# complete generic method taking the csv_keys and the list of candidate lists
		rep_keys = ['Minister', 'prime minister', 'Name of Minister', 'Permanent secretary']
		rep = find_header_match(keys, rep_keys)

		date_keys = ['Date of meeting', 'Date']
		date = find_header_match(keys, date_keys)

		org_keys = ['Name of organisation', 'Organisation', 'Name of External Organisation', 'Name of External Organisation*', 'Name of organisation or individual', 'Person or organisation that meeting was with']
		org = find_header_match(keys, org_keys)

		meet_keys = ['Purpose of meeting', 'purpose of meeting²', 'purpose of meeting_']
		meet = find_header_match(keys, meet_keys)

		#TODO length checks removed, need to handle empty columns
		if rep and date and org and meet:
			self.tabletype = 'meeting'
		elif date and org and meet:
			self.tabletype = 'meeting'
		elif find_header_match(keys, ['date', 'date gift given']) and find_header_match(keys, ['gift']):
			self.tabletype = 'gift'
		elif find_header_match(keys, ['destination']):
			self.tabletype = 'travel'
		elif find_header_match(keys, ['Date of hospitality']):
			self.tabletype = 'hospitality'

@@ -183,16 +183,429 @@
  None%0A%0A%0A
+rep_keys = %5B'Minister', 'prime minister', 'Name of Minister', 'Permanent secretary'%5D%0Adate_keys = %5B'Date of meeting', 'Date'%5D%0Ameet_keys = %5B'Purpose of meeting', 'purpose of meeting%C2%B2', 'purpose of meeting_'%5D%0Aorg_keys = %5B'Name of organisation', 'Organisation', 'Name of External Organisation', 'Name of External Organisation*', 'Name of organisation or individual', 'Person or organisation that meeting was with'%5D%0A%0A%0A
 class Ta
@@ -901,16 +901,17 @@
 header%5D%0A
+%0A
 %09%09# comp
@@ -991,552 +991,130 @@
 %09rep
-_keys = %5B'Minister', 'prime minister', 'Name of Minister', 'Permanent secretary'%5D%0A%09%09rep = find_header_match(keys, rep_keys)%0A%0A%09%09date_keys = %5B'Date of meeting', 'Date'%5D%0A%09%09date = find_header_match(keys, date_keys)%0A%0A%09%09org_keys = %5B'Name of organisation', 'Organisation', 'Name of External Organisation', 'Name of External Organisation*', 'Name of organisation or individual', 'Person or organisation that meeting was with'%5D%0A%09%09org = find_header_match(keys, org_keys)%0A%0A%09%09meet_keys = %5B'Purpose of meeting', 'purpose of meeting%C2%B2', 'purpose of meeting_'%5D
+ = find_header_match(keys, rep_keys)%0A%09%09date = find_header_match(keys, date_keys)%0A%09%09org = find_header_match(keys, org_keys)
 %0A%09%09m

move table header keys out of method