The question:
"Write a one-line Python generator or iterator expression that returns the infinite sequence of increasing integers generated by repeatedly adding the ascii values of each letter in the word “Close” to itself.
67, 175, 286, 401, 502, 569, 677, 788, 903 is the beginning of this sequence.
Assume any needed Python standard library modules are already imported."
This is for learning purposes. I am having difficulty coming up with a solution.
====================================
Edit:Found the answer through helpful comments.The trick is to use itertools.accumulate() and itertools.cycle().accumulate() will add, and cycle() indefinitely repeats.
Solution:
import itertoolsres = itertools.accumulate(itertools.cycle(map(ord, 'Close')))for each in res: print(each)# Prints out:# 67, 175, 286, 401, 502, 569, 677, 788, 903, ... indefinitely!