Let\'s say I have this list of asterisks, and I say it to print this way:
list = [\'* *\', \'*\', \'* * *\', \'* * * * *\', \'* * * * * *\', \'* * * *\']
for
How about this, for a version that mostly uses basic Python operations:
data = ['* *', '*', '* * *', '* * * * *', '* * * * * *', '* * * *']
max_len = max(len(x) for x in data) # find the longest string
for i in range(0, max_len, 2): # iterate on even numbered indexes (to get the *'s)
for column in data: # iterate over the list of strings
if i < len(column):
print column[i], # the comma means no newline will be printed
else:
print " ", # put spaces in for missing values
print # print a newline at the end of each row
Example output:
* * * * * *
* * * * *
* * * *
* * *
* *
*