Can someone tell me how I can get the maximum and the minimum value from a (sub)list?
This is my input:
# einde code omrekenen revit feet naar huidig ingestelde document units
# Hieronder kan je dan gaan programmeren
# Gebruik boiler template
bbox = UnwrapElement(IN[0])
minpoint = []
maxpoint = []
#bbox min and maxpunt
for b in bbox:
b_min = []
b_max = []
for a in b:
b_min.append(a.MinPoint) #Minpoint bbox
b_max.append(a.MaxPoint) #Maxpoint bbox
minpoint.append(b_min) #liststructere
maxpoint.append(b_max) #liststructere
min_pointx = []
min_pointy = []
for min in minpoint:
minx = []
miny = []
for m in min:
minx.append(m.X) #X minpoint
miny.append(m.Y) #Y minpoint
min_pointx.append(min(minx))#liststructere
min_pointy.append(min(miny))#liststructere
max_pointx = []
max_pointy = []
for max in maxpoint:
maxx = []
maxy = []
for m in max:
maxx.append(m.X) #X maxpoint
maxy.append(m.Y) #Y maxpoint
max_pointx.append(max(maxx))#liststructre
max_pointy.append(max(maxy))#liststructre
OUT = max_pointx
bbox = UnwrapElement(IN[0])
minpoint = []
maxpoint = []
#bbox min and maxpunt
for b in bbox:
b_min = []
b_max = []
for a in b:
b_min.append(a.MinPoint) #Minpoint bbox
b_max.append(a.MaxPoint) #Maxpoint bbox
minpoint.append(b_min) #liststructere
maxpoint.append(b_max) #liststructere
min_pointx = []
min_pointy = []
for min in minpoint:
minx = []
miny = []
for m in min:
minx.append(m.X) #X minpoint
miny.append(m.Y) #Y mintpoint
min_pointx.append(minx)#liststructere
min_pointy.append(miny)#liststructere
max_pointx = []
max_pointy = []
for max in maxpoint:
maxx = []
maxy = []
for m in max:
maxx.append(m.X) #X maxpoint
maxy.append(m.Y) #Y maxpoint
max_pointx.append(maxx)#liststructre
max_pointy.append(maxy)#liststructre
OUT = max_pointx
You’ve defined max as a list though. If you’re trying to use max() as a function you have to define the function and use a different name for either the list or the function. Otherwise you have list(item) which means nothing.
import heapq
p = IN[0]
maxout = []
s = 0
for i in p:
maxout.append(heapq.nlargest(1, p[s]))
s += 1
minout = []
s=0
for i in p:
minout.append(heapq.nsmallest(1, p[s]))
s += 1
OUT = maxout, minout