As an experienced python programmer given this input { "underdog": [ { "marketname":…
- User
As an experienced python programmer given this input
{ "underdog": [ { "market_name": "FP", "data": [ { "sport": "TENNIS", "league": "", "market_name": "FP", "display": { "title": "", "player_name": "Alexander Zverev" }, "line": 65.45, "odds": [ { "book": "Underdog (3/5 Pick)", "price": 1.82 } ], "slip_selection": { "over": { "id": "2451ed9e-764f-4d64-bafa-9bcc99d373dc", "choice": "higher", "choice_display": "Higher", "over_under_line_id": "b30986e3-6cc1-44de-81be-37dce173610e", "type": "OverUnderOption" }, "under": { "id": "2a1f32be-3906-4497-94c7-3caf38cabf22", "choice": "lower", "choice_display": "Lower", "over_under_line_id": "b30986e3-6cc1-44de-81be-37dce173610e", "type": "OverUnderOption" } } } ] } ], "prizepicks": [ { "market_name": "FP", "data": [ { "sport": "TENNIS", "league": "", "market_name": "FP", "display": { "title": "", "player_name": "Alexander Zverev" }, "line": 65.45, "odds": [ { "book": "PrizePicks (3/5 Pick)", "price": 1.82 } ], "slip_selection": { "over": { "id": "2451ed9e-764f-4d64-bafa-9bcc99d373dc", "choice": "higher", "choice_display": "Higher", "over_under_line_id": "b30986e3-6cc1-44de-81be-37dce173610e", "type": "OverUnderOption" }, "under": { "id": "2a1f32be-3906-4497-94c7-3caf38cabf22", "choice": "lower", "choice_display": "Lower", "over_under_line_id": "b30986e3-6cc1-44de-81be-37dce173610e", "type": "OverUnderOption" } } } ] } ], "parlayplay": [ { "market_name": "FP", "data": [ { "sport": "TENNIS", "league": "", "market_name": "FP", "display": { "title": "", "player_name": "Alexander Zverev" }, "line": 65.45, "odds": [ { "book": "ParlayPlay (3/5 Pick)", "price": 1.82 } ], "slip_selection": { "over": { "id": "2451ed9e-764f-4d64-bafa-9bcc99d373dc", "choice": "higher", "choice_display": "Higher", "over_under_line_id": "b30986e3-6cc1-44de-81be-37dce173610e", "type": "OverUnderOption" }, "under": { "id": "2a1f32be-3906-4497-94c7-3caf38cabf22", "choice": "lower", "choice_display": "Lower", "over_under_line_id": "b30986e3-6cc1-44de-81be-37dce173610e", "type": "OverUnderOption" } } } ] } ] }find the same player across the underdog, prize picks, parlayplay and any other sites in this input in the future and the same market. Then add that player’s in a dictionary output that has the players name, market and each sites line. The final output should be a list of these dictionaries. - Assistant
You can achieve this by iterating over the input dictionary and collecting the required information for each player in a list of dictionaries. Here's a python code for the same:
input_data = { # your input data goes here } output = [] # Iterate over each site (like underdog, prizepicks, etc.) for site in input_data.values(): for market_data in site: for player_data in market_data["data"]: player_name = player_data["display"]["player_name"] market_name = player_data["market_name"] site_line = player_data["line"] # Check if the player already exists in the output list existing_player = None for item in output: if item["player_name"] == player_name and item["market_name"] == market_name: existing_player = item break if existing_player: # Update the existing dictionary existing_player[site_name] = site_line else: # Add a new dictionary to the output list new_player = { "player_name": player_name, "market_name": market_name, site_name: site_line } output.append(new_player) print(output) - User
as a python programmer write an optimal method to return the players in this list that have a mismatch in underdog, draftking and pinnacle lines. given this list
[{ "player_name": "Jimmy Butler", "market_name": "PRA", "underdog": 39.5, "draftkings": 39.5, "pinnacle": 39.5 }, { "player_name": "Jordin Canada", "market_name": "PA", "underdog": 15.5 }, ] - Assistant
Here's an optimal method to return the players in the list that have a mismatch in their lines for underdog, draftkings, and pinnacle:
def mismatched_lines(players): mismatched_players = [] for player in players: lines = { "underdog": player.get("underdog"), "draftkings": player.get("draftkings"), "pinnacle": player.get("pinnacle") } # Check if at least any two lines exist for a player if sum([1 for line in lines.values() if line is not None]) < 2: continue # Check for any mismatches in the lines unique_lines = set(lines.values()) if None in unique_lines: unique_lines.remove(None) if len(unique_lines) > 1: mismatched_players.append(player) return mismatched_players players = [ { "player_name": "Jimmy Butler", "market_name": "PRA", "underdog": 39.5, "draftkings": 39.5, "pinnacle": 39.5 }, { "player_name": "Jordin Canada", "market_name": "PA", "underdog": 15.5 }, ] result = mismatched_lines(players) print(result)