Question: Python Programming In def main, how can write the for loop so that it only runs k times. SentimentAnalysis.py import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer
Python Programming
In def main, how can write the for loop so that it only runs k times.
SentimentAnalysis.py
import nltk from nltk.sentiment.vader import SentimentIntensityAnalyzer import praw
reddit = praw.Reddit(client_id= 'Wd-WRix4MLXfBQ', client_secret= 'cHqEazflu9bUk_Pi8CjaF1SwTh8', user_agent= 'utepcstest' )
nltk.download('vader_lexicon') sid = SentimentIntensityAnalyzer()
def get_text_negative_proba(text): return sid.polarity_scores(text)['neg']
def get_text_neutral_proba(text): return sid.polarity_scores(text)['neu']
def get_text_positive_proba(text): return sid.polarity_scores(text)['pos']
def get_submission_comments(url): submission = reddit.submission(url=url) submission.comments.replace_more()
return submission.comments
def process_comments(each_obj): if each_obj.replies: for each_reply in each_obj.replies: print(each_reply) process_comments(each_reply) else: return 1
def main(): comments = get_submission_comments('https://www.reddit.com/r/learnprogramming/comments/5w50g5/eli5_what_is_recursion/') for each in comments: print(each.body) process_comments(each) # print(comments[0].body) # print(comments[0].replies[0].body) # print(comments[0].replies[0].replies[0].body)
#neg = get_text_negative_proba(each)
#print(neg)
main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
