From the string sentence = 'we are never ever getting back together' , How can I code the uses list comprehension to reverse the words in the string....
View the step-by-step solution to:

Question

From the string sentence = 'we are never ever getting back together' , How can I code the uses list comprehension

to reverse the words in the string. How can I use the reversed() and join() functions. Albeit, this solution is just one line of code, this is a challenging problem. How can I break this down into multiple steps:


    1) know how to split a string into a list of words.

    2) Reverse the list of words using reversed(). The end result should the a list of the words in reverse order.

    3) Use list comprehension to iterate through the list of reversed words.

    4) Use join() to join the words in the reversed list into a string. 



sentence = 'we are never ever getting back together'

Top Answer

The code is given below... View the full answer

chrome_Q7rYVJFTsg.png

sentence = "we are never ever getting back together"
assentence. split()
b=[word for word in reversed(a) ]
reversed sentence=' '. join(b)
print (reversed sentence)
together back getting...

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question