Need max values in list of tuples, based on position
Pancho
Pancho.Jones at proton.me
Fri Nov 11 05:02:34 EST 2022
On 11/11/2022 07:22, DFS wrote:
>
> [(0,11), (1,1), (2,1),
> (0,1) , (1,41), (2,2),
> (0,9) , (1,3), (2,12)]
>
> The set of values in elements[0] is {0,1,2}
>
> I want the set of max values in elements[1]: {11,41,12}
>
>
>
def build_max_dict( tups):
dict = {}
for (a,b) in tups:
if (a in dict):
if (b>dict[a]):
dict[a]=b
else:
dict[a]=b
return(sorted(dict.values()))
More information about the Python-list
mailing list