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 in Python by ana1504.k
• 7,870 points
46 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 by SDeb
• 13,160 points

Related Questions In Python

0 votes
1 answer
0 votes
0 answers

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

can you give an example? with the ...READ MORE

May 6 in Python by Waseem
• 4,480 points
12 views
0 votes
1 answer

How do I turn a list into numpy array?

Use this line: numpy_array = np.array(list) And printing/displaying the ...READ MORE

answered May 24 in Python by Isha
29 views
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 233 views
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,160 points
114 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 in Python by SDeb
• 13,160 points
45 views