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
• 5,910 points
35 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 9,380 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
• 1,870 points
8 views
+2 votes
2 answers

In a list of dictionaries, how can I find the minimum calue in a common dictionary field.

There are several options. Here is a ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,710 points
22 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 920 points
19 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
• 9,380 points
61 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
• 9,380 points
34 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.