Reading in data to python script with multiple inputs (multiple "indexes")


I’m having a bit of a problem understanding how to handle this. I have a small script to clean up data which works on its own:

but once I add multiple ports and have the indexes grow I’m starting to get errors and I’m apparenlty failing how to understand to use the indexing:




Try removing one of your levels of enumeration. If you have a list like this:

IN = [[[1, 2, 3], 
       [4, 5, 6]]]

IN[0] removes the outermost layer of nesting:

[[1, 2, 3],
 [4, 5, 6]]

Finally, iterating whichever variable you assign IN[0] to would give you two lists of 3 integers:
[1, 2, 3] and [4, 5, 6].

What’s happening is that you’re finally getting down to the individual objects stored in the list, which would be an int in my example, therefore raising a TypeError, which would be 'int is not iterable' here. Writing a recursive function would be a more scalable approach for your use case.

1 Like

Thanks! That worked out. :slight_smile:

I’ll look into that recursive function. Right now I just needed a fairly simple one, but it would perhaps be a good moment to have a deeper look at recursion.