Antorinne
Antorinne

Reputation: 11

Transform a list into a sentence

I am trying to learn python but I had a simple problem in one of my projects. I have a list made of string of characters:

그러니까, 네놈들은
이 무덤의 주인이
아니란 말이냐?

When I print with readlines(), i get:

['그러니까, 네놈들은\n', '이 무덤의 주인이\n', '아니란 말이냐?']

But what I would like to have is:

그러니까, 네놈들은 이 무덤의 주인이 아니란 말이냐?

No line jump, and only a space between the lines content.

I think the solution is quite simple but I can't figure out what I'm doing wrong. I already found some leads but nothing seems to work in my case and I don't know why (I'm probably doing something wrong). These are the leads I already tried but with no success:

  1. Count the number of lines and use a "for"loop to add up all the elements
  2. Convert a list to string

  3. Try to delete some characters (\n)

Thank you for your help

Upvotes: 0

Views: 43

Answers (1)

Óscar López
Óscar López

Reputation: 236004

Try this:

lst = ['그러니까, 네놈들은\n', '이 무덤의 주인이\n', '아니란 말이냐?']
' '.join(w.strip() for w in lst)

Upvotes: 1

Related Questions