Hey,
Im quite new to python and have some issues with what I presume really is a quite easy task…?
Im trying to import a file and filter out (get rid of) all the empty lists so that the remaining data will be more useful, but the "filter(None, list1) doesn’t seem to do anything at all? What am I missing here?
Really greatful for any tips on how to do this.
Code: str = open(filePath) for i in str: list1 = i.split() list2 = filter(None, list1) #does this do anything at all!?? print list2
Awesome, thank you!!! finally I get a grip on this. Your first example works really well, the second one seems to just add them on top of each other so that if we have items items [1], [2], [3], it returns:
what is the function of ‘r’ in open()? That code in contrast to the previously suggested returns the file as one grasshopper index, but still splits it into multiple python items. Do you know what the relation between Grasshopper paths/indexes and python lists and strings are? They seem to be slightly different things?
actually, looking at it again I realize that its “list1” that I want if len(list1)>0:
The appended list just mass additions everything and messes up the grasshopper indexes. Do anyone know what the relation is between python list & strings and GH paths and indices are and how to control them?
What I want is to the left in the picture, but it only works when I print list1 within the if statement. appending it wont help me bring it out of that as you see in the picture to the right… =/