Python Forum
IPython Notebook - How to use a class you have written - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: IPython Notebook - How to use a class you have written (/thread-16961.html)



IPython Notebook - How to use a class you have written - moga2003 - Mar-22-2019

Good evening,

I have completed my first code in Ipython Notebook (as MSword file), and now I need to use the class that I wrote the code for to answer 10 questions at the bottom of the notebook that I have attached.

This is a Text Analyzer. I am supposed to use the code written in the Text Analyzer class and answer the questions. However, I can't find any written help on how to use the class to answer these questions.Can someone please help me understand how this works?

Thank you.


RE: IPython Notebook - How to use a class you have written - snippsat - Mar-23-2019

(Mar-22-2019, 12:41 AM)moga2003 Wrote: I have completed my first code in Ipython Notebook (as MSword file)
Notebook has it own format .ipynb which can eg be shared with nbviewer,MSword should no be used to share Notebooks.
Quote:I can't find any written help on how to use the class to answer these questions.Can someone please help me understand how this works?
To help you get started.
The class is written so it can take in url or text(.txt) files.
They have written in internal parsing in class,eg tag_id is own name they made up.
If parsing straight for BS it had look like this us of id not tag_id:
id_tag = soup.find('div', id='content-main')
id_tag.text
Using class for question 1.
>>> url = 'https://www.webucator.com/how-to/william-henry-harrisons-inaugural-address.cfm'
>>> ta = TextAnalyzer(url)
>>> ta.set_content_to_tag('div', tag_id='content-main')
>>> print("word_count", ta.word_count)
word_count 8430



RE: IPython Notebook - How to use a class you have written - moga2003 - Mar-25-2019

Thank you so much snippsat!!! I would never have figured this out.

And, I will remember nbviewer for future posts

I only have 2 questions left that are stumping me.

Question #2: least common letter. My code accounts for most common word, but it does not break it down into individual characters(letters). How do I change it from most common word, into least common letter?

Question #8: Palindromes. How do I use this code to find palindromes? I've checked and tried a few different ways, but they don't work for this, and honestly, I have never written anything to find a palindrome. From what I have researched, the only thing I have understood is that I am supposed to use this [::-1] in the code.

Any thoughts, or help?

As always, your help is definitely appreciated.

Thank you.