Question

I have two lists of lists which I call old_rows and new_rows.

Each row is a list of exactly 30 items. There may be a very large (and unknown) number of rows in each list. The two lists may contain different numbers of rows.

[ [row1_item1, row1_item2... row1_item30], 
  [row2_item1, row2_item2... row2_item30],
  ....
  [rowN_item1, rowN_item2... rowN_item30] ]

Where N is large and variable.

What I'd like to do is compare old_rows and new_rows and create a list of "significant differences" - I'm only interested in comparing about 10 items between rows. I already have a function which compares two rows for only those items.

So I tried this:

   changes = []
   for o, n in izip_longest(old_rows, new_rows):
      if not o:
         changes.append(output_row(None, n))
         continue
      if not n:
         continue
      if significant_differences(o, n):
         changes.append(output_row(o, n))

Annoyingly, this needs to work in Python 2.4, so izip_longest is out. Also the code for izip_longest doesn't work as the unexplained next isn't 2.4-friendly.

Ideally looking for something pythonic and fast using a generator to cope with potentially very-large lists.

Était-ce utile?

La solution

tuple(map(next, iterators)) 

can be changed to

tuple(i.next() for i in iterators) 

for Py <= 2.6

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top