Gribouillis has allready posted code similar to this in his snippets, but here version for input suitable for for expressions, generators and list comprehensions. Need to add robustness by some try...except blocks for real world use.
# make this code to work in both Python 2 and 3 template from __future__ import print_function, division try: input, range = raw_input, xrange except: pass def input_generator(prompt='> ', stop=''): ''' keep asking for input until stop value entered ''' while True: inp = input(prompt) if inp.lower() == stop.lower(): return yield inp print('Give words for me to capitalize, end by "quit".') print(' '.join(inp.strip().capitalize() for inp in input_generator('word> ', 'quit')))
About the Author
IT Pro doing Eng-Fin-Eng translations