[Python] coding help -- iterating over 2 arrays by individual orderings

Bob Miller kbob at jogger-egg.com
Thu Jan 11 22:58:45 PST 2007


Rob Hudson wrote:

> I want to iterate over them in the order specified by text.item.sequence 
> and media.item.sequence.  Individually text is sorted by sequence and so 
> is media.

Use a Schwartzian transform?

   t_order = [(item.seq, 'a', item.content) for item in text]
   m_order = [(item.seq, 'b', item.content) for item in media]
   for seq, content in t_order + m_order:
	display_text_or_media(content)

The 'a' and 'b' force a text item to precede a media item with the
same sequence number.  If you don't care, leave 'a' and 'b' out.

-- 
Bob Miller                              K<bob>
                                        kbob at jogger-egg.com


More information about the Python mailing list