Add one list as element into a list of list

jbuilder

#1

Hi everyone
I have two lists:
let l1=[[0;0];[1;1]];;
let l2=[2;2];;

I want to put l2 into l1 for l3=[[0;0];[1;1];[2;2]]
can you tell me how to do it,

Thank you in advance


#2

For appending to a list, you could use @:

l1 @ [ l2 ]

I’m not sure if there’s a version of this to append a single element (without needing to wrap it in []). Be aware that this is a less efficient than prepending to the list (l2 :: l1), since you need to iterate to the end of the list to add the new element.