Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Reverse words in a log message

Python data engineering interview problem. Difficulty: beginner. Pattern: Strings. About 10 minutes. Part of the Pro drill bank.

Ops pastes a one-line log message into a ticket. For a postmortem slide they want the words in reverse order while leaving each word itself readable.

Reverse the order of words in a log message. Do not reverse the letters inside a word.

Requirements

  • Split on whitespace into words.
  • Join the reversed word list back into a string.

Constraints

  • Punctuation attached to a word stays with that word.

Examples

Input: reverse_words('retry failed job') Output: 'job failed retry' This input follows the stated rules and produces this output.

Topics: lakebench, python, strings.

More Python interview questions · All interview problems · Learn data engineering

beginner

Reverse words in a log message

Interview-style drill: Reverse the order of words in a log message while keeping punctuation attached to its word.

Reverse the order of words in a log message. Do not reverse the letters inside a word.