List.UniqueItems now working as expected... (2.0.0.4354)

Hi there,

I’m trying to eliminate identical items in the list.
Therefore I try to use the List.UniqueItems node to accomplish that.
But the result is not what I expected, which would be [[1, 2, 3], [1, 2, 3, 4], [2, 3, 4]].
Result is included in the attachment.

Any suggestion is welcome.
Thanks a lot.

UniqueItems

I suppose List.UniqueItems combines list that contains the same items in the same order, even if one has extra items.

Changing the order does seem to affect it but that isn’t a real work around. You could try to make a python script to get an actual unique items list.

1 Like

Python code:

# The inputs to this node will be stored as a list in the IN variables.
unique = []
for i in IN[0]:
	if i in unique:
		continue
	else:
		unique.append(i)
		
OUT = unique

Hasn’t been made to work with nested lists, just only checks on the single level.

4 Likes

Kenny,
Thank you for the amazingly fast reply! :smiley:
So, I guess I need to learn Python… :laughing:

ClarK

No problem! You don’t necessarily need to learn Python. I agree that the current List.UniqueItems is not working as you would think it should. Maybe they could add a bool for if they should combine similar lists or not.

I guess another way around would be to make all the lists the same length (by adding a dummy items at the end of each shorter list) so you can compare them with the List.UniqueItems node, but I guess @kennyb6’s method is by far simpler :slight_smile:

Edit : also, here is a method (that can largely be improved) if you’re delaing with characters (just a raw idea, it could be enhanced :slight_smile: )

2 Likes

@mellouze

Thanks for your idea. :smiley:
But in fact I have to deal with 2-digits (and more) numbers.
I assume this would not be compatible then. :thinking:

ClarK

You could also insert a separator between each two elements ("%" for instance, or any string), and then String.Split to get back the original items, if you want to deal with multiple digits items. I’ll give it a try later.

1 Like

@mellouze

Genius!
It works perfectly! ! :smiley: :smiley:

Edited: String.ToNumber added

1 Like

Make sure you convert back to int but other than that, that is a great way to do it OOTB. Nice one @mellouze

2 Likes

Agreed !

Glad I helped :slight_smile:

Instead of a list.fromsteing node you can get the index of the unique item, and then get the item at index from the prior list. Been awhile but I have executed that workaround awhile back.