# genExpressions.py
'''
generator expressions are another way to construct a
generator object. Generator expressions are almost
identical to list comprehsions. The only syntax
difference between a list comprehension and a generator
expression is [] vs ()... the big difference is that
the list comprehension returns a list, but the
generator expression returns a generator object, which
only evaluates one item at a time without storing any
sequence in memory.

your generator expression can take whatever amount
of logic that you can put between the parentheses
as long as that logic evaluates to a sequence

Example 1: 
evenInts = (n for n in range(10) if n%2 == 0)

Example 2:
numbers = [7, 22, '3', '5']
integers = (int(n) for n in mumbers)

Example 3:
names = ['Don', 'Annie', 'Ron', 'Fannie', 'John', 'Manny']
uppercase = (name.upper() for name in names)
reverse_uppercase = (name[::-1] for name in uppercase)
'''
# main =============================
def main():
	# create a list
	myList = ['one', 'two', 'three']
	
	# create an expression that evaluates to a list
	# and store that list in memory
	listComprehension = [
		item.upper()
		for item in myList
		]
	
	# create generator object that will evaluate
	# one item at a time without storing the sequence
	# in memory
	generatorExpression = (
		item.upper()
		for item in myList
		)
	
	# print the list
	print(myList)
	
	# print the list comprehension 
	print(listComprehension)
	
	# return the generator object
	print(generatorExpression)
	
	# print the list of items generated by
	# the generator object
	print(list(generatorExpression))
	
	# end
	print('Done.')
	
if __name__ == '__main__': main()

