0

My current approach is:

rowiter = atable.where(condition)
rowiter_length = max([i for i, row in enumerate(rowiter)])

Is there a way to get the length of rowiter without looping through the entire iterator?

user12345678
  • 429
  • 1
  • 4
  • 10

1 Answers1

1

Not sure if there's a more efficient way, but you should really just be using len(rowiter) instead of that list comp, for two reasons:

  1. If the iterator object DOES have a more efficient way of calculating its length, it'll most likely have made it accessible via the __len__ special method, so you'll get the speedup if it's available.
  2. enumerate starts at index 0, so your construct will return 1 less than the actual length of the iterator.
tzaman
  • 46,925
  • 11
  • 90
  • 115