kurt
kurt

Reputation: 21

Using Python and Flask

Python with Flask This is my code:

word=input("Type Something: ")
listofwords=word.split()
wordfreq = []
for w in listofwords:
    wordfreq.append(listofwords.count(w))
    print("Word: "+str(listofwords)+ "\n")
    print("Count: "+str(wordfreq) + "\n")

My code works fine. My only problem is that it prints it out horizontally: Word: ['is', 'the', 'bus', 'at', 'the', 'terminal'] Count: [1, 2, 1, 1, 2, 1]

How do I have my results printout vertically like this: Word Count "is" 1 "the" 2 "bus" 1 "at" 1 "the" 2 "terminal" 1

Also, which parts of my code should I put under "tr" and "td" in the table section of my html. I already have Word and Count under "th" and it works fine.

Upvotes: 2

Views: 24

Answers (1)

Vasyl Lyashkevych
Vasyl Lyashkevych

Reputation: 2232

In python 3.x: You must call additional the function:

print() 

For example:

for w in listofwords:
    wordfreq.append(listofwords.count(w))
    print("Word: "+str(listofwords))
    print()
    print("Count: "+str(wordfreq))
    print()

More information you can get here.

Upvotes: 1

Related Questions