Question

Write a loop in python that can get the first 10 categories in python.

Display on the first 10.

In [20]: import newspaper In [21]: cnn_papernewspaper.build(http://www.cnn.com) In [46]: for article in cnn_paper.articles: print(article.url) In [28]: for category in cnn_ paper.category_urls(): print(category) http://www.cnn.com/more http://www.cnn.com/asia http://www.cnn.com http://www.cnn.com/accessibility http://www.cnn.com/world http://www.cnn.com/opinions http://www.cnn.com/business http://collection.cnn.com http://www.cnn.com/election https://money-cnn.com http://www.cnn.com/style http://www.cnn.com/transcripts http://www.cnn.com/politics http://www.cnn.com/middle-east http://ww.cnn.com/europe http://www.cnn.com/health http://www.cnn.com/entertainment http://www.cnn.com/vr http://www.cnn.com/uk http://tours.cnn.com http://www.cnn.com/travel http://ww.cnn.com/videos http://cnn. İt http://www.cnn.com/australia http://www.cnn.com/africa http://www.cnn.com/americas http://www.cnn.com/us

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the code below.

CODE

============

# first get the categories

categories = cnn_paper.category_urls()

# now find the minimum of categories length and 10

# if there are less than 10 categories, print all of them

length = min(10, len(categories))

# now, print categories upto length

for i in range(length):

print(categories[i])

1 # first get the categories 2 categories - cnn_paper.category urlsO 4 # now find the minimum of categories length and 10 5 # if there are less than 10 categories, print all of them 6 lengthmin (10, len(categories)) 8 # now, print categories upto length 9 for i in range(length) 10 print(categoriesil)

Add a comment
Know the answer?
Add Answer to:
Write a loop in python that can get the first 10 categories in python. Display on...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT