How do I print this list vertically

0 votes
I have this list of asterisks, and I want to print it this way:

list = ['* *', '*', '* * *', '* * * * *', '* * * * * *', '* * * *']
for i in list:
    print i
So here, the output is:

* *
*
* * *
* * * * *
* * * * * *
* * * *
But what do I do if I want the output to be vertical, like this:

* * * * * *
*   * * * *
    * * * *
      * * *
      * *
        *

Please provide me with the code that will print it vertically.
Apr 5, 2019 in Python by ana1504.k
• 7,910 points
5,565 views

1 answer to this question.

0 votes
You can try the following code:

myList = ['* *', '*', '* * *', '* * * * *', '* * * * * *', '* * * *']
import itertools
for i in itertools.izip_longest(*myList, fillvalue=" "):
    if any(j != " " for j in i):
        print " ".join(i)
 

This will give the following Output

* * * * * *
*   * * * *
    * * * *
      * * *
      * *  
        *
answered Apr 5, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

how do i print only the last two letters in a string using regular expression in python?

$ to match the end of the ...READ MORE

answered Mar 15, 2019 in Python by Waseem
• 4,540 points
932 views
0 votes
1 answer

how do i get the list of all the keys in my dictionary?

my_dict = {'one': 'first', 'two': 'second', 'three': ...READ MORE

answered Sep 30, 2020 in Python by VJ_python
812 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer

In Python, how do I read a file line-by-line into a list?

with open(fname) as f:     content = f.readlines() # you ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,300 points
1,792 views
0 votes
1 answer

How do I check if a list is empty?

You can try the following: if not a:   print("List ...READ MORE

answered Mar 14, 2019 in Python by SDeb
• 13,300 points
878 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP