Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Python to solve the questions tweets = [ The United States Navy sent a guided-missile destroyer through the Taiwan Strait on Thursday, the first

Use Python to solve the questions

tweets = [ "The United States Navy sent a guided-missile destroyer through the Taiwan Strait on Thursday, the first time a US warship has gone through the waterway that separates China and Taiwan during the Biden administration.", "Internet and news services continue to be disrupted across Myanmar as the country's military seeks to secure their grip on power after deposing the democratically-elected government.", "House Republicans vote to keep Rep. Liz Cheney in leadership after she defended her impeachment vote.", "Senate approves a power-sharing agreement that formally hands over control of committees to Democrats.", "House Democrats will take the first steps to remove Rep. Marjorie Taylor Greene from her committee assignments, Majority Leader Hoyer says.", "The Justice Department drops a Trump administration lawsuit that accused Yale University of discriminating against Asian American and White applicants.", "This year's Golden Globes nominees are a mix of old and new, highlighting what we've been watching from home during the pandemic. Read the list:", "Myanmar's ousted civilian leader, Aung San Suu Kyi, has been remanded in custody for two weeks under import-export laws, her party says.", "President Biden paid his respects to Capitol Police Officer Brian Sicknick, whose remains lie in honor after he was killed in the insurrection.", "The House of Representatives has officially created a new rule that will fine any member for failing to complete security screening prior to entering the House floor.", "Amazon CEO Jeff Bezos is stepping down later this year, and will transition to the role of executive chair.", "Face masks are now required in US national parks when visitors can't maintain physical distance and in all National Park Service buildings.", "The Senate confirms Alejandro Mayorkas as Homeland Security secretary. He is the first Latino and immigrant to serve at the helm of the department.", "Legendary Emmy and Tony Award-winning actor Hal Holbrook has died, his daughter confirms. Holbrook portrayed iconic author Mark Twain in one-man shows for more than six decades.", "FBI Director Christopher Wray identified the agents killed in the Sunrise, Florida, shootout as Special Agent Daniel Alfin and Special Agent Laura Schwartzenberger." ]

1. Write a for loop using Python that iterates the strings in tweets printing only the strings that have fewer than 120 characters. Use the print function to print a string. Printed strings are separated by a new line.

2. Using list comprehension, create a new list name "ABC" from tweets such that the new list has only the first 30 characters of each string in tweets followed by '...'. For example, the first two items in ABC are 'The United States Navy sent a ...' and 'Internet and news services con...'.

*** Make sure to use list comprehension as opposed to using a basic for loop.

# Check your answer here. (Do not make any change to this cell. Just run this cell.) len(ABC[0]) == 33 # Expected output: True

3. Write a function get_first_3_tokens that takes a string s as an argument, splits the string with space into a list of word tokens, and then returns a list of the first three items in the list.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago