输入一行字符串,然后对其进行如下处理。
输入格式:
字符串中的元素以空格或者多个空格分隔。
输出格式:
逆序输出字符串中的所有元素。
然后输出原列表。
然后逆序输出原列表每个元素,中间以1个空格分隔。注意:最后一个元素后面不能有空格。
输入样例:
a b c e f gh
输出样例:
ghfecba
['a', 'b', 'c', 'e', 'f', 'gh']
gh f e c b a
实现
#!/usr/bin/env python3
#-*- coding:utf-8 -*-
from functools import reduce
def main():
s=input().split();
a=s.copy()
s.reverse();
print(f"{reduce(lambda x,y:x+y,s)}",a,reduce(lambda x,y:x+y,map(lambda x:x if x==s[-1] else x+' ',s)),sep="\n")
#----------
main()
输出
a b c e f gh
ghfecba
['a', 'b', 'c', 'e', 'f', 'gh']
gh f e c b a
Q.E.D.