python - More efficient ways of doing this -


for in vr_world.getnodenames():     if != "_error_":          world[i] = vr_world.getchild(i) 

vr_world.getnodenames() returns me gigantic list, vr_world.getchild(i) returns specific type of object.

this taking long time run, there anyway make more efficient? have seen one-liners loops before supposed faster. ideas?

kaloyan suggests using generator. here's why may help.

if getnodenames() builds list, loop going on list twice: once build it, , once when iterate on list.

if getnodenames() generator, loop doesn't ever build list; instead of creating item , adding list, creates item , yields caller.

whether or not helps contingent on couple of things. first, has possible implement getnodenames() generator. don't know implementation details of function, it's not possible if that's case. next, number of items you're iterating on needs pretty big.

of course, none of have effect @ if turns out time-consuming operation in of vr_world.getchild(). that's why need profile code.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -