# Python index of max value in 2D list

**URL:** <https://forum.inductiveautomation.com/t/python-index-of-max-value-in-2d-list/75811>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [July 1, 2023, 1:35pm UTC](https://forum.inductiveautomation.com/t/python-index-of-max-value-in-2d-list/75811 "2023-07-01T13:35:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [July 1, 2023, 1:35pm UTC](https://forum.inductiveautomation.com/t/python-index-of-max-value-in-2d-list/75811/1 "2023-07-01T13:35:33Z")

</div>

`counts = [["08:00", 50], ["08:15", 47], ["08:30": 66], ["08:45", 52] ]`

How do I find the time of the greatest count?

`max(zip(*.counts)[1])` will return the value 66.

I'm looking for some version of `counts.index()` to be return the index so I can retrieve the time (which in the application is a proper datatime datatype) from column 0.

Thanks.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 1, 2023, 1:55pm UTC](https://forum.inductiveautomation.com/t/python-index-of-max-value-in-2d-list/75811/2 "2023-07-01T13:55:31Z")

</div>

```python
import operator

counts = [["08:00", 50], ["08:15", 47], ["08:30", 66], ["08:45", 52] ]

sortedCounts = sorted(counts, key=operator.itemgetter(1))

print sortedCounts

maxItem = sortedCounts[-1]

print maxItem

```

Output:

```plaintext
[['08:15', 47], ['08:00', 50], ['08:45', 52], ['08:30', 66]]
['08:30', 66]

```

Or, if you don't care what happens to the original list:

```python
counts = [["08:00", 50], ["08:15", 47], ["08:30", 66], ["08:45", 52] ]
print count

counts.sort(key = lambda row:row[1])
print counts

maxItem = counts[-1]
print maxItem

```

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 1, 2023, 4:10pm UTC](https://forum.inductiveautomation.com/t/python-index-of-max-value-in-2d-list/75811/3 "2023-07-01T16:10:54Z")

</div>

You can also use `max`:

```python
max(your_list, key=itemgetter(1))

```
