I have a dictionary mapping an id_ to a list of data values like so: dic = {id_ : [v1, v2, v3, v4]}
.
I'm trying to iterate through every value in the dictionary and retrieve the max/min of a certain index of the list mappings.
What I want to do is something like this:
maximum = max([data[0], ??) for id_, data in self.dic.items()])
...but obviously this will not work. Is it possible to do this in one line as above?
You need to use it something like this:
maximum = max(data[0] for data in dic.values())
since you are not using your keys
, simply use dict.values()
to get just the values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With