Float is not iterable

Hello Dynamo Friends,

I want to do something like this:

	for x in xList:
		if x>=0 and x<=180: 
			do something
		else:
			do something else

But I`m getting a “Float is not iterable” error.

Can someone please light me up on how to do this?

Kind Regards :slight_smile:

Your code is expecting a list when you’re providing a single float.

1 Like

Hi @gerhard.p ,

Is there a specific reason you are doing this in Python? With some simple DesignScript you can also achieve this, just plot this code into a Code Block:

x >= 0 && x <= 180 ? x+180 : x ;

where as: query ? true : false ;

1 Like

I need this for a larger python script :slight_smile:

So why does this work with a single float:

NumberList = range (5,60,8)
resultList = []

for x in NumberList:

	if x<30:
		result = "Potato"
	else:
		result = "Tomato"
		
	resultList.append(result)
	
OUT = resultList

What do you mean? That code does exactly what you’d expect. Each number in NumberList returns Potato if <30 or Tomato if not. What were you expecting as the output?

2 Likes

Yes, i was wondering why this test code works but my other code not.

I´m sorry it seems that it was just a list level problem, it works now. Had to add a list level to the angles.

for grids, angles, view in zip(gridList, angleList, viewList):

	for grid, angle in zip(grids, angles):
		if angle<90 and angle>45:	
			grid.ShowBubbleInView(DatumEnds.End1,view) 
			grid.HideBubbleInView(DatumEnds.End0,view)
		else:
			grid.ShowBubbleInView(DatumEnds.End0,view)
			grid.HideBubbleInView(DatumEnds.End1,view)
1 Like

a small trick :slightly_smiling_face:

if 45 < angle < 90:

2 Likes