2

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.