def analyze_word(word, pos_words, neg_words):
'''
(str, list, list) -> int
Given a word, a list of positive words (all in lowercase),
and a list of negative words (all in lowercase), return
whether
or not the word is positive, negative or neutral.
For a positive word, return 1.
For a negative word, return -1.
For a neutral word (one that does not appear in either the
negative words list nor the positive words list), return 0.
>>> ("happy", ['happy', 'love'], ['sad',
'angry'])
1
>>> ("angry", ['happy', 'love', 'joy'], ['sad', 'angry',
'bad'])
-1
>>> ("LOVE", ['happy', 'love', 'joy'], ['sad', 'angry',
'bad'])
1
>>> ("sAd", ['happy', 'love', 'joy'], ['sad'])
-1
>>> ("okay", ['happy', 'love', 'joy'], ['sad',
'angry'])
0
'''
Python
def analyze_word(word, pos_words, neg_words): ''' (str, list, list) -> int Given a word, a list of positive words (all in lowercase), and a list of negative words (all in lowercase), return whether or not the word is positive, negative or neutral. For a positive word, return 1. For a negative word, return -1. For a neutral word (one that does not appear in either the negative words list nor the positive words list), return 0. >>> ("happy", ['happy', 'love'], ['sad', 'angry']) 1 >>> ("angry", ['happy', 'love', 'joy'], ['sad', 'angry', 'bad']) -1 >>> ("LOVE", ['happy', 'love', 'joy'], ['sad', 'angry', 'bad']) 1 >>> ("sAd", ['happy', 'love', 'joy'], ['sad']) -1 >>> ("okay", ['happy', 'love', 'joy'], ['sad', 'angry']) 0 ''' word = word.lower() if(word in pos_words): return 1 elif(word in neg_words): return -1 else: return 0
def analyze_word(word, pos_words, neg_words): ''' (str, list, list) -> int Given a word, a list...
def most_expensive_item(price_list: List[list]) -> str: """Return the name of the most expensive item in price_list. Precondition: price_list is a list of lists in the following format: [ [str, int], [str, int], ... ] where each 2-element list represents a name (str) and a price (int) of an item. price_list has at least one element. >>> price_list = [["apple", 1], ["sugar", 5], ["mango", 3], ... ["coffee", 9], ["trail mix", 6]] >>> most_expensive_item(price_list) """ please complete the function body in Python
def contains_hashtag(valid_tweet: str, tweet_word:str) -> bool: '''Return True if the valid tweet contains the tweet word, with a hashtag at the beginning. Tweet can contain multiple tweet words. >>>contains_hashtag('I like #csc108', 'csc108') True >>>contains_hashtag('I like #csc108', 'csc') False >>>contains_hashtag('I like #csc108, #mat137, and #phl101', 'csc108') True pls finish this function by using python string method(do not use advance methods)
PYTHON --create a program that accepts a list of words and returns the longest word inside that list can only use --- append, len, str, float, range, strip, split, int --create a program that accepts a list of words and a specific length. function will returns a new list that contains the words found with the specific length, and return an empty list if none are found can only use --- append, len, str, float, range, strip, split, int
def do_action(decision, game_data, current_location, inventory): ''' (int, dict, float, list) -> str Given the game data dict, and the current location ID, get all the possible actions at that location. If the decision number given as 'decision' falls outside the number of allowed actions at this location, then return the string "Invalid decision. Please select choice from the decisions listed." Make sure this string is EXACTLY as above. Else, if the decision is valid, then figure out the location information...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...
In Python 3 only please. A simple function that will be used on a file. commonpair(str) – Takes a single string argument, representing the first word. This function should return the word that most frequently followed the given argument word (or one of, in case of ties). If the argument word does not appear in the text at all, or is never followed by another word (i.e., is the last word in the file), this function should return None. I...
Function name: crazy_scrabble Parameters : word (string), current points (int), double word score (boolean) Returns: int Description: You are playing scrabble with a friend, and you thought you knew how to calculate how many points you have, but your friend suddenly starts making up all these crazy rules. Write a function that helps keep track of how many points you have with these new rules: ●Each 'k', 'm', 'p', 'x', 'y', and 'z' earns you 7 points. ●'c' and 's'...
IN PYTHON 3 LANGUAGE, please help with function, USE RECURSION ONLY def im(l: 'an int, str,list,tuple,set,or dict') -> 'an int, str, tuple, or frozenset' pass SAMPLE OUTPUT: The following call (with many mutable data structures) imm(1) returns 1 imm('a') returns 'a' imm( (1, 2, 3)) returns (1, 2, 3) imm( frozenset([1, 2, 3])) returns frozenset({1, 2, 3}) imm( [1, 2, 3, 4, 5, 6]) returns (1, 2, 3, 4, 5, 6) imm( [1, 2, [3, [4], 5], 6]) ...
SIGN_GROUPS = '[ARI,LEO,SAG]-[TAU,VIR,CAP]-[GEM,LIB,AQU]-[PIS,SCO,CAN] def find_astrological_compatibility(sign_1, sign_2): ''' (str, str) -> int Given two 3-character strings representing star signs, return an int representing how compatible they are. According to Bob's rules, the compatibility between signs is calculated based on the SIGN_GROUPS they belong in, as follows: - If the signs are in the same group, return 100 - If both the signs are in an odd-numbered group (i.e. 1 and 3) OR if both are in an even group (i.e. 0...
Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...