Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert list to multiline string?

Tags:

python

I have the following list:

["Jargon", "Hello", "This", "Is", "Great"]

I want to populate a string with:

"""
{}
""".format(list-elements-besides-the-first)

Is there a simple one liner I could use to make it such that I can:

  1. get all the elements of the array (besides the first element) and shove it into the {}?
  2. Is it possible to make it so that each element shows up in its own line?
like image 512
Rolando Avatar asked Nov 29 '22 01:11

Rolando


1 Answers

"""
{}
""".format("\n".join(items[1:]))
like image 129
John Kugelman Avatar answered Dec 08 '22 00:12

John Kugelman