Hi,

I am writing a cgi script for a web database query "results" page and I need to display the results in an html table. My question: 'Is there a way to print out a list of words without the commas and the square brackets?' e.g if this is the list: is there a way i can get it to print cat, dog, mouse, rat (exactly in the green text format ?

I tried running a loop like this:

for word in list:
            print word,

but that breaks up the columns of the table since each list consist of different numbers of elements. If u have any ideas, i'd be glad to know.

Thanks in advance,

ymf

Recommended Answers

All 4 Replies

for word in list:
            print word+",",

or did i just miss what you asked?

I tried ur method what actually happens is the display on pic1. I need it to look like pic2 but without the commas and square brackets. e.g have just canis_familiaris, dog, domestic dog not the whole .

Pic1 is ok, but it breaks up the columns into pieces which is not good enough

Hope my question is clear...

PS. files attached are pic1.jpg and pic2.jpg

Thats ok, I think i figured out a way to solve it!

I use a string function to store each word and then print out the string itself. I'll post it up just in case anyone's interested

line = "" # the string function that stores each word in the list
for word in mlist:
     line = line + word + ", "
print line

Yes indeed that is a good way to solve it. Now i have looked at the pictures i can see what your problem really was. And yes how you have done it is correct

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.