- #1
mathmari
Gold Member
MHB
- 5,049
- 7
Hey!
I want to write a one-line Python generator or iterator expression that returns the sequence of integers generated by repeatedly adding the ascii values of each letter in the word “Close” to itself. The first 10 integers in this sequence are: 67, 175, 286, 401, 502, 569, 677, 788, 903, 1004. If the code should not be in one line it would be as follows, or not ?
So that we write that in oe line the for-loop will be
right? But how do we add at this line the print? :unsure:
I want to write a one-line Python generator or iterator expression that returns the sequence of integers generated by repeatedly adding the ascii values of each letter in the word “Close” to itself. The first 10 integers in this sequence are: 67, 175, 286, 401, 502, 569, 677, 788, 903, 1004. If the code should not be in one line it would be as follows, or not ?
Code:
sum = 0
for letter in list("Close") :
sum += ord(letter)
print(sum)
Code:
sum += [ord(letter) for letter in list("Close")]