coordinatesf = "Aberdeen Scotland"
new_word=[]
#split the two words
words = coordinatesf.split(" ")
#reverse the second and put to lowercase
words[1]=words[1][::-1].lower()
#populate the new string
for index in range(0,len(words[0])):
new_word.insert(2*index,words[0][index])
for index in range(0,len(words[1])):
new_word.insert(2*index+1,words[1][index])
outstring = ''.join(new_word)
print outstring
这将拆分输入,将第一个单词与反向的第二个单词分开,连接成对的单词,然后连接成对的单词列表
有点脏,但很管用:
请注意,只有当输入字符串由两个长度相同的单词组成时,才需要定义好。 我用断言来确保这是真的,但你可以不说
可以用sum()替换x[0]+x[1]部分,但我认为这会降低可读性
相关问题 更多 >
编程相关推荐