Finding the max and min in dictionary as tuples python

2024/10/8 18:32:03

so given this dictionary i'm trying to find the max value and min value

{'Female' :[18,36,35,49,19],'Male' :[23,22,6,36,46]}

the output should be in tuples for example key: (min,max)

Female: (18,49)
Male: (6,46)
Answer
{key:(max(d[key]),min(d[key])) for key in d}

This will return

{'Female': (49, 18), 'Male': (46, 6)}
https://en.xdnf.cn/q/118686.html

Related Q&A

Flask sqlalchemy relations across multiple files

Im new to Flask Sqlalchemy and I want to declare multiple models and relate them to each other, I followed the example in the documentation but I keep getting this error sqlalchemy.exc.InvalidRequestEr…

Parsing XML with Pykml

I have the following xml file I got from QGIS<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.…

Python Google App Engine Receiving a string in stead of JSON object

I am sending a HTTP POST request from android to a server using the script belowURI website = new URI("http://venkygcm.appspot.com");HttpClient client = new DefaultHttpClient();HttpPost reque…

Creating Gui for python client server

Help needed with my python project. Unable to get the code for the client or server implemented with the Gui i created. it is one based on book seller where the client is the buyer and the server is th…

Maximum Subarray sum - Where is my solution wrong? Kadanes Algorithm

Here is a description of the problem:The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: max_sequence([-2, 1, -3, 4, -1, 2,…

Pandas: Selecting rows and columns based on a subset of columns that contain a certain value

Lets say I have a dataframe with column names as follows:col_id_1, col_id_2, ..., col_id_m, property_1, property_2 ..., property_nAs an example, how would I search across all col_ids for, say, the valu…

Open a image file then display it in new window

I have a button in my GUI then after selecting a image file I want it to display in new window.Code:import tkinter as tk from tkinter import * from tkinter import ttk from tkinter import filedialog …

python plotting chart in interactive viewer vscode

This works and shows a plot in vscode: #%% cell with plot import matplotlib.pyplot as plt y = [3.2, 3.9, 3.7, 3.5, 3.02199] x = [0.15, 0.3, 0.45, 0.6, 0.75] n = [155, "outliner", 293, 230, 67…

Find all lines in a dataframe that matches specific pattern and extract the strings after split

I have a dataframe that looks like LineEntry: [0x0000000002758261-0x0000000002758268): /a/b/c:7921:14 LineEntry: [0x0000000002756945-0x0000000002756960): /f/b/c:6545:10 LineEntry: [0x00000000027562c9-0…

Python: Concatenate many dicts of numpy arrays with same keys and size

I have a function called within a loop that returns a dict (dsst_mean) with roughly 50 variables. All variables are numpy arrays of length 10.The loop iterates roughly 3000 times. Im current concatenat…