mirror of
https://github.com/rasbt/python_reference.git
synced 2025-01-31 13:43:48 +00:00
Merge branch 'master' of https://github.com/rasbt/python_reference
This commit is contained in:
commit
212453aa3c
12
get_minmax_indeces.py
Normal file
12
get_minmax_indeces.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# Sebastian Raschka, 03/2014
|
||||||
|
# Getting the positions of min and max values in a list
|
||||||
|
|
||||||
|
import operator
|
||||||
|
|
||||||
|
values = [1, 2, 3, 4, 5]
|
||||||
|
|
||||||
|
min_index, min_value = min(enumerate(values), key=operator.itemgetter(1))
|
||||||
|
max_index, max_value = max(enumerate(values), key=operator.itemgetter(1))
|
||||||
|
|
||||||
|
print('min_index:', min_index, 'min_value:', min_value)
|
||||||
|
print('max_index:', max_index, 'max_value:', max_value)
|
Loading…
Reference in New Issue
Block a user