Python Forum
Score each word from list variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Score each word from list variable
#1
Hi, I have a list comprised of a tweet and score.
I'd like to split the tweet into words and assign the total score of the tweet to each word.
Any help is much appreciated, new to Python! Thanks


 
Tweet_list = [('You better believe you're beautiful', 3),('Happy Birthday to my friends',4)] 

def word_sentiment(): 
    list_words = [] 
    for tweet in tweet_list: 
        for word in tweet.split(" "): 
            list_words.append((word)) 
    return list_words 


Desired output:
Output:
[('You',3) ('better',3) (believe',3) ('you're',3) ('beautiful',3) ('Happy',4) ('Birthday',4) ('to',4) ('my',4) ('friends',4) ]
Reply


Messages In This Thread
Score each word from list variable - by pythonias2019 - Jun-12-2019, 11:54 AM
RE: Score each word from list variable - by stullis - Jun-13-2019, 04:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  For Word, Count in List (Counts.Items()) new_coder_231013 6 7,043 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  Split string using variable found in a list japo85 2 2,200 Jul-11-2022, 08:52 AM
Last Post: japo85
  find some word in text list file and a bit change to them RolanRoll 3 2,428 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 3,685 Aug-12-2021, 04:25 PM
Last Post: palladium
  An IF statement with a List variable dedesssse 3 22,961 Jul-08-2021, 05:58 PM
Last Post: perfringo
  Create variable and list dynamically quest_ 12 6,618 Jan-26-2021, 07:14 PM
Last Post: quest_
  Trying to get the first letter of every word in a list DanielCook 2 4,012 Jan-05-2021, 05:06 PM
Last Post: deanhystad
Question Matching variable to a list index Gilush 17 8,771 Nov-30-2020, 01:06 AM
Last Post: Larz60+
  Print variable values from a list of variables xnightwingx 3 3,469 Sep-01-2020, 02:56 PM
Last Post: deanhystad
  Trying to find first 2 letter word in a list of words Oldman45 7 6,032 Aug-11-2020, 08:59 AM
Last Post: Oldman45

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020