[Tutor] sorting into lists

Daniel Yoo dyoo@CSUA.Berkeley.EDU
Sat, 21 Sep 2002 19:21:27 -0700 (PDT)


On Sat, 21 Sep 2002, Magnus Lycka wrote:

> At 23:32 2002-09-20 -0500, Tim Wilson wrote:
> >etc. The reason I need the list of lists is because it's the most
> >obvious way I can think of to iterate over the events and print the date
> >at the beginning of each inner loop. (Think nested for loops.)
>
> Think again! :)
>
> oldDate = None
>
> for element in straightList:
>      date = getDate(element) # you figure it out
>      if date != oldDate:
>          print date
>          oldDate = date
>      print detailsToPrint(element)
>
> Why make it more complicated than that?

This looks much better for Tim's task.  At least, this approach is simpler
than forming mathematical equivalence classes.  *grin*

We need to make sure that our straightList is sorted by date, so that
common elements are grouped together sequentially, but Tim has to do that
anyway to display his events in chronological order.