Data Structures & AlgorithmsModerateTCS NQT · Python basics

Problem: What does the following print?

Problem: What does the following print?
print(' '.join('the sky is blue'.split()[::-1]))
  1. A. the sky is blue
  2. B. eht yks si eulb
  3. C. blue is sky the
  4. D. blue the is sky

Correct answer: C. blue is sky the

split() creates the word list, [::-1] reverses it, and join puts the words back with single spaces. Reversing each word's letters instead would give the trap eht yks si eulb.

More Coding Interview Problems questions

Exams that ask this topic