hi all,
using ghpythonlib, it would be possible to know how many nested iterations a list contains?
Maybe provide an example of what you intend to accomplish. I don’t get it!
Hi @diff-arch,
x = [ [ [ 1, 2, 3 ] ] ]
for i in x: # iterations nested 0
for j in i: # iterations nested 1
for w in j: # iterations nested 2*
print w # Result Nested Iterations
I’m interested in knowing if there is a function or method that returns me the number of nested interactions.
example: method/function(x) = 2* ( return in this case the number 2 )
Something like this?
nums = [[[1, 2, 3]]]
count = 0
for i in nums:
for j in i:
for k in j:
print(count)
count += 1
count += 1
count +=
# 0, 1, 2
This includes counting items, but it would also be possible to only count the sublists.
the execution of the for loop was just an example, I asked if there was a function or a method precisely because I don’t have to run the list loop but the intent is only to know the number of nested iterations a priori without running the loop.
How about simply refactoring the example code above into a function yourself?
I don’t think that’s possible, knowing a priori without inspecting.
I had tried, I was also hoping there might be some Gh component so I could call it via the ghpythonlib library