I currently have two set lists that combine “steps” and “time”:
step = 1,1,1,1,2,2,2,2
time = 1,2,5,6,1,3,5,6
These values directly correlate, meaning a tuple looking like [(1,1),(1,2),(1,5),(1,6),(2,1),(2,3),(2,5),(2,11)]
Basically I’m trying to find the max value for step 1, and the min value of step one, as well as min/max for step 2
minstep1 = 1
maxstep1 = 6
minstep2 = 1
maxstep2 = 11
how can I accomplish this in python? do i need to create a multidimensional list? is there a function that can iterate keyvalue pairs of a tuple that I can just use the zip function?
Thanks!
You’re looking for
itertools.groupby. Here is some example code for your question:It groups
timebystepthen finds theminandmaxfor each group. Alternatively, you could do something like:To group by
stepwithoutzipping withtime.