Currently you have a single loop which outputs the corresponding asterisk until the number is reached. You also need to take into account the whitespace. What I would do is output a space for the number opposite the current index number of the asterisk being printed out.
This is to say that if the list passed in to the function is [1,2,3]
then on the first iteration, two spaces and a * should be printed: ' *'
and on the next iteration, one space and two * should be printed: ' **'
on the third iteration, three * should be printed: '***'
Edit:
I went ahead and coded my implementation even though corn3lius' answer was already fantastic. I included his here and also the doc tests so you can see how it works.
The main difference between my answer and corn3lius' is that the left-hand white space is hard-coded in corn3lius' answer and mine is generated based on the maximum number inside the given list.
def BarGraphify1(nums):
'''
see http://stackoverflow.com/a/23257715/940217
>>> BarGraphify1([1,2,3])
*
**
***
'''
for num in nums:
print " {:>10}".format("*" * num)
def BarGraphify2(nums):
'''
>>> BarGraphify2([1,2,3])
*
**
***
>>> BarGraphify2([1,3,2])
*
***
**
'''
output = []
maxVal = max(nums)
for n in nums:
space = (maxVal-n)*' '
asterisks = n*'*'
output.append(space + asterisks)
print '\n'.join(output)
if __name__ == '__main__':
import doctest
doctest.testmod()
Edit #2:
Now that I see that the OP wanted columns as shown in the edit, I've reworked my solution to use the numpy.transpose function. Much of it remains the same, but now I treat the whole thing as rows and columns, then transpose the 2-D array to get the desired columns.
import numpy
def BarGraphify3(nums):
'''
>>> BarGraphify3([1,2,3])
*
**
***
>>> BarGraphify3([1,3,2])
*
**
***
'''
grid = []
maxVal = max(nums)
for n in nums:
space = (maxVal-n)*' '
asterisks = n*'*'
grid.append(list(space + asterisks))
cols = []
for row in numpy.transpose(grid):
cols.append(''.join(row))
print '\n'.join(cols)