I have a list:
mylist = [
"hello", "my", "name", "is", "frank", "and", "it", "is", "great", "to", "be", "here", "in", "this", "great", "country"
]
and am using
for i in range(0,len(mylist)):
print(mylist[i])
to print out each item and it works as it prints out every word in a new line.
What I would like to do is to be able to treat multiple words in the list as one by changing the value of a variable k
:
i.e I would like to instead of it outputting
hello
my
name
is
frank
and
it
is
great
to
be
here
in
this
great
country
I would like to if k = 2
to output
hello my
name is
frank and
it is
great to
be here
in this
great country
should there be an odd number of items in the list, the last word should be alone in a line
if k = 3
then there should be 3 words in a line
Is there any way to do this
Thank you in advance