[Facebook data engineer coding] Write a function that, given a string representing a sentence, returns the sentence with the words in the same order but the letter in each word reversed.

Data Science Interview QuestionsCategory: Data Engineer Coding[Facebook data engineer coding] Write a function that, given a string representing a sentence, returns the sentence with the words in the same order but the letter in each word reversed.
MockInterview Staff asked 10 months ago

Sample run:
“I love programming” –> “I evol gnimmargrop”

3 Answers
MockInterview Staff answered 10 months ago

def rev_string(phrase):
phrase_lst = phrase.split(‘ ‘)
rev_phrase = ”
for p in phrase_lst:
rev_phrase += p[::-1] + ‘ ‘
return rev_phrase.strip()
rev_string(“I love programming”)

PS answered 8 months ago

def reversewordsnotsentence(sentence) : words =sentence.split() newsen=[] for word in words: word=word[::-1] newsen.append(word) return \” \”.join(newsen)

PS answered 8 months ago

def reversewordsnotsentence(sentence) :
words =sentence.split()
newli=[]

for word in words:
word=word[::-1]
newli.append(word)

return ” “.join(newli)

print(reversewordsnotsentence( “the cattle was rattled by the battery”))

Your Answer

7 + 7 =