Concatenate for each entry by two sub lists

#1

Having some trouble working out the logic for a particular task. I want to create new entries in Alice with each L0 entry in Bob concatenated to each L0 entry in Alice, but only for each L3 in Bob

Each L1 element in Alice’s L3 list0 should be duplicated and concatenated for each element in Bob’s L2 list 0, and each L1 element in Alice’s L3 list1 should be duplicated and concatenated for each element in Bob’s L2 list 1

the desired output, below; I’ve omitted all L2 sublists for brevity.
[
[
[1aA1
1aA2
1aA3
1aB1
1aB2
1aB3
1aC1
1aC2
1aC3]
…]
[
[2aA4
2aA5
2aA6
2aB4
2aB5
2aB6]
…]
]

Right now, it just adds Bob’s L2 to Alice’s L2. I think it has something to do with using the … Cycle node? Wanted to see if I can get some advice.

0 Likes

#2

Something like this?

0 Likes

#3

Couldn’t figure out a good way of doing it using nodes as that level of cross product + list level is pretty complicated.

Here is a python script that works for the list structure you have shown:

alice = IN[0]
bob = IN[1]

L3 = []
for alic, bo in zip(alice, bob):
	L2 = []
	for ali in alic:
		L1 = []
		for al in ali:
			for b in bo:
				L1.append(al + b)
		L2.append(L1)
	L3.append(L2)

OUT = L3

2 Likes

#4

So, I got this to work, but I don’t understand how it actually works. It’s probably because I don’t understand well enough how the map and other first order functions work.

@JacobSmall @Konrad_K_Sobon I know y’all are busy guys, but maybe you could give some insight?

0 Likes