My third kata, write a function `check_generator` that examines the status of a Python generator expression `gen` and returns `'Created'`, `'Started'` or `'Finished'`. For example:

`gen = (i for i in range(1))` >>> returns `'Created'` (the generator has been initiated)

`gen = (i for i in range(1)); next(gen, None)` >>> returns `'Started'` (the generator has yielded a value)

`gen = (i for i in range(1)); next(gen, None); next(gen, None)` >>> returns `'Finished'` (the generator has been exhuasted)

For an introduction to Python generators, read: https://wiki.python.org/moin/Generators.

Please do vote and rank the kata, and provide any feedback.

Hint: you can solve this if you know the right module to use.

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def check_generator(gen):
	

Solutions:
def check_generator(gen):
	if gen.gi_frame is None:
		return 'Finished'
	if gen.gi_frame.f_lasti == -1:
		return 'Created'
	return 'Started'


from inspect import getgeneratorstate as gt
d = {'GEN_CREATED': 'Created', 'GEN_SUSPENDED': 'Started'}

def check_generator(gen):
	return d.get(gt(gen), 'Finished')


import inspect

def check_generator(gen):
	state = inspect.getgeneratorstate(gen)
	return [['Created', 'Started'][state == 'GEN_SUSPENDED'], 'Finished'][state == 'GEN_CLOSED']


from inspect import getgeneratorstate

def check_generator(gen):
	_ = getgeneratorstate(gen)
	if _ == 'GEN_CREATED':
		return 'Created'
	if _ == 'GEN_RUNNING' or _ == 'GEN_SUSPENDED':
		return 'Started'
	else:
		return 'Finished'


from inspect import getgeneratorstate

def check_generator(g):
	return {'R': 'Created', 'U': 'Started', 'L': 'Finished'}[getgeneratorstate(g)[5]]


def check_generator(gen):
	if not gen.gi_frame:
		return 'Finished'
	if gen.gi_frame.f_lasti == -1:
		return 'Created'
	return 'Started'


check_generator = lambda g: {'GEN_CREATED': 'Created', 'GEN_CLOSED': 'Finished'}.get(__import__('inspect').getgeneratorstate(g), 'Started')


from inspect import getgeneratorstate

def check_generator(gen):
	state = getgeneratorstate(gen)
	if state == 'GEN_CREATED':
		return 'Created'
	elif state == 'GEN_SUSPENDED':
		return 'Started'
	else:
		return 'Finished'


from inspect import getgeneratorstate as gg

def check_generator(gen):
	return {'GEN_CREATED': 'Created', 'GEN_SUSPENDED': 'Started', 'GEN_CLOSED': 'Finished'}[gg(gen)]


def check_generator(gen):
	if gen.gi_frame != None:
		if len(gen.gi_frame.f_locals.keys()) == 1:
			return 'Created'
		else:
			return 'Started'
	if gen.gi_frame == None:
		return 'Finished'