[Tutor] Print a list in columnar format
Bob Gailer
bgailer at alum.rpi.edu
Thu Oct 7 00:28:04 CEST 2004
At 02:27 PM 10/6/2004, Michael Knowles wrote:
>Two more newbie questions regarding printing to standard output (not a text
>file). (I'm using version Python 2.3.4 on Win2000)
>
>This is the section of code which creates my results:
>
> elif choice == 1:
> aou = raw_input("\nEnter AOU or species: ")
> results = [x for x in aou_species if x.lower().find(aou) != -1]
> results.sort()
> print "\nResults of ", aou, "\n", results
>
>
>One (this one feels like I should know it, but...):
>How do I print/display a list in column format? For example, my results
>are displayed as in the Python Shell window:
>
> ['04550 Dusky-capped Flycatcher \n', '24550 White-breasted
>Wood-Swallow \n']
>
>but I would like:
>
> 04550 Dusky-capped Flycatcher
> 24550 White-breasted Wood-Swallow
>
print "Results of", aou
for result in results:
print result
>Two:
>Some of my results may have more species than can fit on my cmd window. Is
>there a way to tell Python to stop printing at say 20 species and wait for
>the user to hit the Enter key before printing the next 20 species, etc?
lines = 20
for x in range(0, len(results), lines):
for result in results[x:x+lines]
print result
raw_input('Hit Enter to continue')
>Thanks in advance,
Welcome in retrospect
>This is a very useful site
Yep
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell
More information about the Tutor
mailing list