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,890 points
2,195 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,250 points

Related Questions In Python

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
150 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 in Python by VJ_python
60 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, 2019 in Python by Isha
109 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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,466 views
0 votes
0 answers
0 votes
2 answers

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

readline function help to  read line in ...READ MORE

answered Jun 21 in Python by sahil
• 540 points
291 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,250 points
110 views