New list with largest value among sublists ; Python, Lists

#1

I am trying to get biggest value among sub-lists and produce one list
not sure why it does work as expected

Code.txt (455 Bytes)

0 Likes

#2

@Michal_Dengusiak You need answer in Python or OOTB nodes?

0 Likes

#3

0 Likes

#4

Yes I need python as I need better understand codes

0 Likes

#5

your code has a couple of issues, you set the value of Xcurrent and you’re appending a value to pairs list at each iteration .
Try this:

maxlist = []
for i in IN[0]:
	max = i[0]
	for k in i:
		if k>max:
			max = k
		else:
			pass
	maxlist.append(max)

OUT = maxlist

also, python has a built in max method :

2 Likes

#6

Hi it is not max value form each sub-lists… we take each element among sublists and then find largest…all sublist got same lenght

0 Likes

#7

aslo we have some empty cells in lists… so will be no value in some as well

0 Likes

#8

the function works with nulls as well :

we take each element among sublists and then find largest
i’m not sure I got this part

0 Likes

Python Nodes Basics
#9

here is example:
[ ] [2]
[3] [ ]
[ ] [5]
[7] [2]

result should be

[2]
[3]
[5]
[7]

0 Likes

#10

@Michal_Dengusiak - Not sure if this is what you are looking for, but we have a node that returns the maximum item and will replicate through sublists…works with nulls as well…

Additionally, your initial list looks like it has empty values which will likely be interpreted as strings. You may want to replace those as null values.

Hope that helps.

capture.dyn (5.2 KB)

1 Like