Python: len function in Dynamo

Hello
Is there any limitation for the use of the len() function in Dynamo?
I am trying to make an “if” statement. Something like:

a = [0,1,[‘a’,‘b’,‘c’]]
i = 0

while i<len(a):
i=i+1
else:
print(i)

I attached the error message.
Any tip of what is going on would be really appreciated

No, there is no limitation. What the error is pointing is lst_ordem_p_aux[i] is an integer and len doesn’t apply to numbers.

I think you need to re-look at your length checks because a list with 1 item within is classed as a length of 1, where as a empty list is counted as 0.

Below example highlights this for you by using ootb “list.count” node with a use level setting to check sublists instead of the main list.

Side note:

  • It seems you are adding one to contador twice(61 and 68), shouldn’t this only be done once on line 68 otherwise you may miss some data.
  • I think you need to re-check all of the logic between lines 47 and 69 because it seems a lot more complex and may keep re-adding same data or get to a point where it is out of “range”.
  • Why are you using if statements instead of a for loop(see below example)?

Thanks for the reply people!
I am still having some problems though…
@Brendan_Cassidy , the list.count level @L3 is what i whant…
I tried again to be sure (i didnt know i could have more than one output… this will help me to make more verifications at each new phase)
My conclusion… no idea… first i thought that my problam was the function len() with multi-level lists. But when i use the list i created as an input in another program that used de len() function it worked as a charm! But the same function, if called in the first code, causes de “int not callable” error.

len() function as separeted script / len() function inside the script (error)

@Brendan_Cassidy About the side notes:
First… thanks for the tips!
I lear python in the beguinning of last year and i tried to apply more complex logic functions. I created a test using know variables and it worked but when i bring it to dynamo it didnt… sience didnt know how to trobleshoot i got tired and used a simple i = i+1 that i tought it was foulproff
The “Contador” is present in 2 ocasions becaus the first is adding 1 every time it writes at the register and the second subtracts 1 at the end. I was trying to create a loop that reapeted itself until there where no logs in the register… than it would go strait to counter-1, so counter==0 and then it would exit the loop… probably it would still need a looooooooooooot more polishing but this len() question was driving me crazy… haha

i will post the images again separately…

You are having the issue because you have used “len” as one of your variables, this is bad practice to name something that is actually used as a function!

Refer to line 23 in your code because you have made len become a “int” (output from “len()”) instead of its original function of calculating the length of a list.

You need to always name your variables as something that is not already a function, try to use something as follows.
inputList= IN[0]
inputListTotal = len(inputList)

Owwwwwww!!! Indeed! It’s really wrong!
I change the variable and it worked fine!
Thanks a lot!