Change list structure to match another list structure

This looks amazing! and would have taken me months to work out haha. However, It appears having a count @L1 (I think its this) errors out my dynamo 1.3 so I cant try it :frowning: Opening the script in Dynamo 2.0 just shuts down revit and dynamo instantly.

Specified cast is not valid.

   at ProtoCore.DSASM.Heap.ToHeapObject[T](StackValue heapObject)
   at ProtoCore.Lang.Replication.AtLevelHandler.GetElementsAtLevel(StackValue argument, Int32 level, List`1 indices, Boolean recordIndices, RuntimeCore runtimeCore)
   at ProtoCore.Lang.Replication.AtLevelHandler.<>c__DisplayClass0_0.<GetElementsAtLevel>b__1(StackValue v, Int32 i)
   at System.Linq.Enumerable.<ZipIterator>d__61`3.MoveNext()
   at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at ProtoCore.Lang.Replication.AtLevelHandler.GetArgumentAtLevel(StackValue argument, AtLevel atLevel, RuntimeCore runtimeCore)
   at ProtoCore.Lang.Replication.AtLevelHandler.GetArgumentsAtLevels(List`1 arguments, List`1 atLevels, RuntimeCore runtimeCore)
   at ProtoCore.Lang.Replication.AtLevelHandler.GetArgumentAtLevelStructure(List`1 arguments, List`1 atLevels, RuntimeCore runtimeCore)
   at ProtoCore.DSASM.Executive.Callr(Int32 blockDeclId, Int32 functionIndex, Int32 classIndex, Boolean& explicitCall, Boolean isDynamicCall, Boolean hasDebugInfo)
   at ProtoCore.DSASM.Executive.CALLR_Handler(Instruction instruction)
   at ProtoCore.DSASM.Executive.Execute(Int32 exeblock, Int32 entry, Language language)
   at ProtoCore.DSASM.Executive.Execute(Int32 exeblock, Int32 entry, List`1 breakpoints, Language language)
   at ProtoCore.DSASM.Executive.BounceUsingExecutive(Executive executive, Int32 exeblock, Int32 entry, StackFrame stackFrame, Int32 locals, Boolean fepRun, Executive exec, List`1 breakpoints)
   at ProtoScript.Runners.ProtoScriptRunner.ExecuteLive(Core core, RuntimeCore runtimeCore)
   at ProtoScript.Runners.LiveRunner.Execute(Boolean isCodeCompiled)
   at ProtoScript.Runners.LiveRunner.CompileAndExecute(List`1 astList)
   at ProtoScript.Runners.LiveRunner.CompileAndExecuteForDeltaExecution(List`1 astList)
   at ProtoScript.Runners.LiveRunner.SynchronizeInternal(GraphSyncData syncData)
   at ProtoScript.Runners.LiveRunner.UpdateGraph(GraphSyncData syncData)
   at Dynamo.Scheduler.UpdateGraphAsyncTask.HandleTaskExecutionCore()
   at Dynamo.Scheduler.AsyncTask.Execute()

The count @L1 works in other scripts. I wonder if this python code replacing the emptys with a value to keep the list structure is doing somthing funky.

list = IN[0]
replace = IN[1]
out = []

for l in list:
	if l == []:
		out.append(replace)
	else:
		out.append(l)

OUT = out