Ask a small girl - "How old are you?". She always says strange things... Lets help her!


For correct answer program should return int from 0 to 9.

Assume test input string always valid and may look like 
"1 year old" or "5 years old", etc.. The first char is number only.

Difficulty: EASY
Starter code: def get_age(age):
	

Solutions:
def get_age(age):
	return int(age[0])


import re

def get_age(age):
	return int(re.search('\\d+', age).group())


def get_age(age):
	for x in age:
		if x.isdigit():
			return int(x)


def get_age(age):
	if age == '0 years old':
		return 0
	elif age == '1 years old':
		return 1
	elif age == '2 years old':
		return 2
	elif age == '3 years old':
		return 3
	elif age == '4 years old':
		return 4
	elif age == '5 years old':
		return 5
	elif age == '6 years old':
		return 6
	elif age == '7 years old':
		return 7
	elif age == '8 years old':
		return 8
	elif age == '9 years old':
		return 9
	else:
		return 1


def get_age(age):
	age = age[0]
	age = int(age)
	if age > 9 or age < 0:
		return 0
	else:
		return age


def get_age(age):
	return int(age[:1])


import re

def get_age(age):
	return int(re.match(pattern='(?P<age_char>^\\d.)', string=age).group('age_char'))


get_age = lambda s: int(s[0])


def get_age(age):
	return int(''.join(filter(str.isdigit, age)))


def get_age(age):
	return int(__import__('re').search('\\d+', age).group(0))


def get_age(n):
	return int(n[0])


def get_age(age):
	char = []
	for a in age:
		char.append(a)
	return int(char[0])


def get_age(age):
	return [int(s) for s in age.split() if s.isdigit()][0]


def get_age(age):
	a = [int(s) for s in age.split() if s.isdigit()]
	for i in a:
		return i


def get_age(age):
	for i in list(age):
		return int(i[0])


def get_age(age):
	return int(age[0])
reply = '2'
print(get_age(reply))


def get_age(age):
	return [int(c) for c in age if c.isnumeric() == True][0]


def get_age(age):
	return eval(age.split()[0])


def get_age(age):
	my_List = list(age)
	a = age[0]
	return int(a)


def get_age(age):
	num = age[0:1]
	return int(num)


def get_age(age):
	z = age.split()
	return int(z[0])


import re

def get_age(age):
	pattern = re.compile('[0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9]+')
	return int(re.findall(pattern, age)[0])


def get_age(age):
	int_age = [str(i) for i in str(age)]
	return int(int_age[0])
print(get_age('2 years old'))


import re

def get_age(age):
	return int(''.join(re.findall('\\d', age)))


def get_age(age):
	return int(''.join([i for i in age.split() if i.isdigit()]))


def get_age(age):
	for i in age:
		if i.isnumeric():
			return int(i)
		else:
			pass


def get_age(age):
	return [int(chr) for chr in age if chr.isdigit()][0]


def get_age(age):
	age = age.replace('years', '')
	age = age.replace('year', '')
	age = age.replace('old', '')
	age.rstrip()
	age = int(age)
	return age


def get_age(age):
	extracted = list(age)[0]
	return int(extracted)


def get_age(age):
	newlist = age.split()
	print(newlist)
	numbers = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
	age = []
	for i in newlist:
		for x in numbers:
			if i == x:
				age.append(i)
	final = int(''.join(age))
	return final
get_age('5 years old')


def get_age(age):
	return int(age[0]) if 0 <= int(age[0]) <= 9 else 'idk'


def get_age(age):
	import re
	return int(re.findall('\\A\\d', age)[0])


def get_age(age):
	return int(age[0]) if age[0].isdigit() else ''


def get_age(age):
	return int(age[:age.index(' ')])


import unittest

def get_age(age):
	return int(age.split()[0])

class TestGetAge(unittest.TestCase):

	def test_should_return_2_when_string_age_has_2(self):
		age = '2 years old'
		actual = get_age(age)
		self.assertEqual(actual, 2)


def get_age(age):
	liste = age.split()
	return int(age[0])


def get_age(age):
	ages = age.split(' ')
	return int(age[0])


def get_age(age):
	for item in age:
		if item.isnumeric():
			return int(item)


def get_age(age):
	value = age.split()[0]
	print(value)
	return int(value)


def get_age(age):
	print('how old are U?')
	get_age = age[0]
	return int(get_age)


def get_age(age):
	return int(age[0])
	print('{} year old'.format(age))


def get_age(age):
	age = list(age.split(' '))[0]
	if age.isdigit():
		return int(age)
	return 0


def get_age(age):
	for i in age:
		if i == '2':
			return 2
		elif i == '4':
			return 4
		elif i == '5':
			return 5
		elif i == '1':
			return 1
		elif i == '3':
			return 3
		elif i == '6':
			return 6
		elif i == '8':
			return 8
		elif i == '7':
			return 7
		else:
			return 9


def get_age(age):
	return int(age.replace(' ', '').split('year')[0])


import re

def get_age(age):
	num = re.search('^(?P<age>\\d+)\\s', age)
	return int(num.group('age'))


def get_age(age):
	res = int(age.split()[0])
	return 0 if 0 > res > 9 else res


def get_age(age):
	i = str(age[0])
	for i in age:
		return int(i)


def get_age(age):
	for i in range(0, 10):
		age = age[i]
		return int(age)


def get_age(age):
	if 'year old' in age:
		return 1
	else:
		return int(age[0])


def get_age(age):
	for num in '0123456789':
		if num in age:
			return int(num)


def get_age(age):
	k = str(age)
	for i in k:
		if i.isdigit() == True:
			return int(i)


def get_age(age):
	for item in age[0]:
		return int(item)


def get_age(age):
	ages = list(age)
	return int(ages[0])


import re

def get_age(s):
	return int(re.search('\\d+', s).group(0))


def get_age(age):
	print('How old are you?')
	if type(age) == int:
		return age
	elif type(age) == str:
		ageInt = int(age[0])
		return ageInt


def get_age(age):
	for x in age:
		return int(x[0])


def get_age(age):
	for (index, character) in enumerate(age):
		if character.isnumeric():
			return int(character)


def get_age(age):
	age = age.split()
	d = ''
	for i in age:
		d += i
		return int(d)


def get_age(age):
	for years in age:
		return int(years)


import re

def get_age(age):
	return int(age[0])


def get_age(age):
	print(age + 'years old')
	return int(age[0])


import re

def get_age(age):
	r = re.compile('^(\\d+) years old$')
	m = r.match(age)
	if m:
		return int(m.group(1))
	else:
		return 1


def get_age(age):
	tmpString = age.split(' ')
	a = int(tmpString[0])
	return a


def get_age(age):
	for c in age:
		if c.isdigit():
			return int(c)


import re

def get_age(age):
	for element in re.findall('[0-9]', age):
		return int(element)


def get_age(age):
	res = [int(i) for i in age.split() if i.isdigit()]
	return res[0]


def get_age(age):
	str = ''
	for i in age:
		if i.isnumeric():
			str = str + i
	return int(str)


def get_age(age):
	str = age
	str_list = str.split()
	for element in str_list:
		if element.isdigit():
			return int(element)


def get_age(age):
	l = list(age)
	i = l[0]
	return int(i)


def get_age(age):
	liste = str(age)
	old = liste[0]
	wer = int(old)
	return wer


def get_age(age):
	for i in range(len(age)):
		return int(age[0])


get_age = lambda s: ord(s[0]) - ord('0')


def get_age(age):
	return int(age[0])
get_age('2 years old')
get_age('4 years old')
get_age('5 years old')
get_age('7 years old')


import re

def get_age(age):
	an = re.sub('\\D+', '', age)
	rean = int(an)
	return rean


def get_age(age):
	girl_list = age.split()
	if int(girl_list[0]) > 0 and int(girl_list[0]) <= 9:
		return int(list(age)[0])


def get_age(age):
	for i in age:
		i = int(i)
		return i


import random

def get_age(age):
	return int(age[:1])


def get_age(age):
	return [int(ch) for ch in age if ch.isdigit()][0]