Skip to content Skip to sidebar Skip to footer

Replacing 3 Lists With 2 Generators

I want to optimize my application using generators and instead of creating 3 lists I want to use 2 generators. Here's the short scheme of my app in it's current version: 1) Load da

Solution 1:

You could possibly make the unpacking more efficient...

self.data_stream = struct.unpack_from('>{}H'.format(self.rows*self.columns), data_file)

The reduce the looping to something like:

for rowno, cols inenumerate(self.data_stream[i:i+self.columns] for i in xrange(0, len(self.data_stream), self.columns)):
    for colno, col inenumerate(cols):
        # col == value, (rowno, colno) = indexif col == 0:
            pass# do somethingelse:
            pass# do something else

note - untested

Post a Comment for "Replacing 3 Lists With 2 Generators"