PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Take two strings from input and reverse their order
storing the first string in a temporary file.
https://www.sololearn.com/Discuss/1701781/a-better-way-to-reverse-input-order
"""
#Define generator which returns one character at a time (lazy)
def char_generator(s):
for c in s:
yield c
return
gen = char_generator(input())
#Write the first string into a temp file
with open('temp', 'w') as f:
while True:
val = next(gen)
if val == " ":
break
f.write(val)
#Fetch the rest of the characters and print them
while True:
try:
print(next(gen), end='')
except StopIteration:
break
#Print a whitespace and the first string from file
with open('temp', 'r') as f:
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run