Appearance
question:Write a python function to analyze a list of archaeological artifact descriptions and identify those related to fertility cults. Each artifact description is a string in the list, and we want to determine if the description contains any of the following keywords: "fertility", "goddess", "mother", "womb", or "birth". The input will be a list of strings, each representing an artifact description. The output should be a list of booleans, where each boolean indicates whether the corresponding artifact description contains any of the specified keywords.For example, given the input:```pythonartifacts = [ "This is a small figurine of a goddess.", "A pottery shard depicting hunting scenes.", "An engraved stone with symbols of birth and motherhood."]```The expected output should be:```python[True, False, True]```This function will help in categorizing and focusing on descriptions that are likely related to the fertility cults, an area of great interest in Neolithic studies.
answer:def analyze_fertility_artifacts(artifacts): fertility_keywords = ["fertility", "goddess", "mother", "womb", "birth"] result = [] for artifact in artifacts: artifact_lower = artifact.lower() contains_keyword = any(keyword in artifact_lower for keyword in fertility_keywords) result.append(contains_keyword) return result
question:Write a python function to help a native resident of Madera city determine the shortest bus route from a list of available routes. The function should take in a list of tuples, where each tuple represents a bus route with the starting point, destination, and the number of stops in between. The function should also take a starting point and a destination as inputs. The output should be the route with the fewest stops between the specified starting point and destination.Here's the input and expected output:Input:- A list of routes, each represented as a tuple: [(start, destination, stops), ...]- A starting point (string)- A destination (string)Output:- A tuple representing the route with the fewest stops, or None if no route is available.Example:```pythonroutes = [ ("A", "B", 5), ("A", "C", 2), ("B", "C", 3), ("A", "D", 4), ("C", "D", 1)]shortest_route = find_shortest_route(routes, "A", "D")print(shortest_route) # Output should be: ("A", "D", 4)```Note: If there are multiple routes with the same number of stops, you can return any one of them.
answer:def find_shortest_route(routes, start, end): graph = {} for route in routes: src, dest, stops = route graph.setdefault(src, []).append((dest, stops)) graph.setdefault(dest, []).append((src, stops)) queue = [(start, [start])] visited = set() while queue: node, path = queue.pop(0) if node == end: return (path[0], path[-1], len(path) - 1) visited.add(node) for neighbor, stops in graph.get(node, []): if neighbor not in visited: queue.append((neighbor, path + [neighbor])) return None
question:Write a python function to filter out artworks from a given list that are associated with Jeff Koons. Each artwork in the list is represented as a dictionary with keys 'title', 'artist', and 'year'. The function should take in a list of such dictionaries and return a new list containing only the artworks not created by Jeff Koons. For simplicity, assume all artist names are strings in the format "Firstname Lastname".Input:- A list of dictionaries, where each dictionary has the following structure: ```python [ {'title': 'Balloon Dog', 'artist': 'Jeff Koons', 'year': 1994}, {'title': 'The Physical Impossibility of Death in the Mind of Someone Living', 'artist': 'Damien Hirst', 'year': 1991}, {'title': 'Tulips', 'artist': 'Jeff Koons', 'year': 1995}, # More artworks... ] ```Output:- A new list of dictionaries containing only the artworks not created by Jeff Koons.Example:```pythoninput_artworks = [ {'title': 'Balloon Dog', 'artist': 'Jeff Koons', 'year': 1994}, {'title': 'The Physical Impossibility of Death in the Mind of Someone Living', 'artist': 'Damien Hirst', 'year': 1991}, {'title': 'Tulips', 'artist': 'Jeff Koons', 'year': 1995}, {'title': 'Untitled', 'artist': 'Cindy Sherman', 'year': 1989}]expected_output = [ {'title': 'The Physical Impossibility of Death in the Mind of Someone Living', 'artist': 'Damien Hirst', 'year': 1991}, {'title': 'Untitled', 'artist': 'Cindy Sherman', 'year': 1989}]```Please provide a solution that efficiently performs this filtering task.
answer:def filter_non_koons_artworks(artworks): return [artwork for artwork in artworks if artwork['artist'] != 'Jeff Koons']
question:Write a python function to convert a list of RGB color values into hexadecimal color codes. The function should take a list of tuples, where each tuple contains three integers corresponding to the red, green, and blue components of a color (each ranging from 0 to 255). The function should return a list of strings, where each string is the hexadecimal representation of the respective color, prefixed with a "#" symbol.For example, given the input list `[(255, 0, 0), (0, 255, 0), (0, 0, 255)]`, the function should return the list `["#FF0000", "#00FF00", "#0000FF"]`.
answer:def rgb_to_hex(rgb_list): hex_colors = [] for r, g, b in rgb_list: hex_color = "#{:02X}{:02X}{:02X}".format(r, g, b) hex_colors.append(hex_color) return hex_colors
question:Write a python function to identify and count keywords related to pregnancy discrimination in a list of sentences. The function should take in a list of strings as input, where each string represents a sentence. The output should be an integer representing the total count of sentences that contain one or more of the specified keywords. The keywords to search for are "pregnancy", "termination", "discrimination", and "rights".Input:- A list of strings, e.g., `["I was terminated due to pregnancy", "This is unrelated", "There is discrimination happening"]`Expected Output:- An integer representing the count of sentences containing at least one keyword.Example:```pythoninput_sentences = ["I was terminated due to pregnancy", "This is unrelated", "There is discrimination happening"]output = 2 # Because the first and third sentences contain keywords.```
answer:def count_pregnancy_discrimination_sentences(sentences): keywords = ["pregnancy", "termination", "discrimination", "rights"] count = 0 for sentence in sentences: sentence_lower = sentence.lower() for keyword in keywords: if keyword in sentence_lower: count += 1 break return count
question:Write a python function to calculate the average sentiment score of a list of text reviews. Each review is a string, and you have a pre-defined dictionary that maps certain words to sentiment scores ranging from -1 (very negative) to +1 (very positive). Words not in the dictionary should be ignored in the sentiment calculation. The function should take as input:- A list of strings, where each string represents a single review.- A dictionary where keys are strings (words) and values are integers or floats (sentiment scores).The function should return:- A float representing the average sentiment score of all the reviews, rounded to two decimal places.Example:```pythonreviews = [ "I love this product, it's fantastic and amazing", "This is awful, I hate it and it's terrible", "Quite decent and satisfactory", "Absolutely wonderful service"]sentiment_dict = { "love": 1, "fantastic": 1, "amazing": 1, "awful": -1, "hate": -1, "terrible": -1, "decent": 0.5, "satisfactory": 0.5, "wonderful": 1}# Expected output: 0.44```
answer:def calculate_average_sentiment(reviews, sentiment_dict): total_sentiment = 0 num_reviews = 0 for review in reviews: review_sentiment = 0 words = review.split() for word in words: if word.lower() in sentiment_dict: review_sentiment += sentiment_dict[word.lower()] if review_sentiment != 0: total_sentiment += review_sentiment num_reviews += 1 if num_reviews == 0: return 0.0 else: return round(total_sentiment / num_reviews, 2)