题目描述:
The input is an English sentence as a string, we need a function - “function convert($input)” that can transform it as described below and return a new string.
The sentence would contain only alphabet (a-z and A-Z) and space, each word would be separated by exactly one space. There would be no spaces before and after the sentence.
Please return the string with each word spelled in reverse, however, the position of the capitalization of each letter should stay the same for each word
For example:.
Input: Many people spell MySQL incorrectly
Output: Ynam elpoep lleps LqSYM yltcerrocni
import string
def str_negative_sequence(str):
a=str.split()
c=str.split()
print(a)
for i in range(len(a)):
a[i]=a[i][::-1]
d=list(a[i])
e=list(c[i])
for j in range(len(e)):
if e[j].isupper() is True:
d[j]=d[j].upper()
else:
d[j]=d[j].lower()
a[i]=''.join(d)
print(a[i])
print(a)
b=' '.join(a)
return b
网友评论