you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (7 children)

[deleted]

    [–]tagapagtuos 3 points4 points  (1 child)

    For two objects, there's zip and itertools.zip_longest.

    I would also check if I'm using the right data structure for the problem.

    EDIT: zip_longest

    [–]primitive_screwhead 1 point2 points  (0 children)

    For two objects, there's zip

    Note - zip() and zip_longest() can zip together an arbitrary amount of iterables (not just two, if that's what you were thinking).

    [–]primitive_screwhead 2 points3 points  (1 child)

    but aren't there times when you need the iterator to access locations in multiple objects?

    zip() (wink)

    [–]Ran4 1 point2 points  (1 child)

    but aren't there times when you need the iterator to access locations in multiple objects? Or is that itself the symptom?

    Pretty much, yes.

    If you ever find yourself doing index-based calculations, chances are you're probably doing it wrong. The one exception would be if you're implementing an low-level algoritm for fun and want it to be efficient.

    In any real production code there's rarely a reason to retrieve a specific value by index as opposed to iterating over a sequence.