[Python] coding help -- iterating over 2 arrays by individual
orderings
Quentin Hartman
qhartman at gmail.com
Thu Jan 11 13:53:55 PST 2007
On 1/11/07, Rob Hudson <rob at euglug.net> wrote:
> Another thought was to iterate and check if text.item.sequence is
> greater than media.item.sequence and pull which ever one is lower.
>
> That seems ok to me but I'm thinking this is a common enough thing that
> there's probably a Pythonic way of doing it that I'm not aware of. Is
> there? :)
I don't know of any method that would be more Pythonic to achieve what
it sounds like you want.
I don't that I have enough information about what you are doing to
make suggestions, but it sounds like you want to have both the text
and media items to have something done to them in order, according to
their sequence number, correct? If that's the case (and depending on
how the lists/dictionaries/whatever are originally built) I would feed
them both into one dictionary and then sort that by the sequence, and
then just iterate over the whole thing. The built-in sort function is
known to be pretty fast, and this method would save a lot of
extraneous comparisons. It would probably be easier logic to manage as
well.
--
-Regards-
-Quentin Hartman-
More information about the Python
mailing list