Combination of two lists with conditions


#1

Hey, i would like to combine these two lists.

The Problem is, that i don´t know how to create these condition:

When the first entry of the first list is the same like the first entry of the second list (+h), than add the second entry of the second list to the first entry of the first list.

best regards
Thore


#2
  1. String.StartsWith to test if the item in the integers list starts the first item in the sub lists of the suffix list.

  2. Get the item at index 1 of each sublist.

  3. Add a dash before each of those string values (you may need to convert to a string first).

  4. Use the test in step 1 to perform an if statement to return the dash combined suffix value when true, when false return an empty string.

  5. Use a + node to join the integer list and suffix value list together.


#3

Okay, thank you for your Reply. But unfortunatly the String.startswith is only searching for the first entry of the list… in this case ,1h´´.


#4

Cross product lacing on your String.StartsWith.

Come to think of it with the H added to the end of the list you may be better off with an == node instead of the String.StartsWith node from a speed standpoint. Hard to say.


#5

Had some fun with python:

Python code:

vals = IN[0]
check = IN[1]

vallist = []
for v in vals:
    checkvalue = [t for t in check if str(v)+"h" == t[0]]
    vallist.append(checkvalue[0])

OUT = ["%s - %s" %(i,v) for i,v in vallist]

Edit: Looking back at the first post and your latest, did you want the h in the final string?


#6

Ok now make it work on level 2 of a 6 deep nested list. :stuck_out_tongue:


#7

Give me an example of the structure. I would like to practice more recursion and lambda functions.


#8

I’ll PM you to keep this closer to the original topic.


#9

Nice, thank you very much! And yes, ich want the ,h´´ in the final string, so everything is optimal :slight_smile: