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,205 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
692 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
534 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,060 views
0 votes
1 answer
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, 2020 in Python by sahil
• 580 points
1,467 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
586 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