ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] for x in myClass
by Danny Yoo other posts by this author
Sep 2 2003 7:40AM messages near this date
[Tutor] Helping with homework --- reasons for sometimes holding back | Re: maint@20974 or before broke mp2 ithreads test
Hi Brian,


> > Your second array, called the tag array, would start out unsorted as:
> >
> > [0, 1, 2, 3]
> >
> > Then sorted it would be:
> >
> > [2, 0, 3, 1]
> 
>  Ok, this looks like the sort is preceding in decending order.  Just
>  wanted to raise that point, since most references to "sorting" assume
>  that we want things in ascending (or more correctly, "nondecending")
>  order.


I'm totally, completely wrong here.  I don't know what the heck I was
thinking.  The sort above is definitely nondecending, not decending.
Sorry about that.



>  Somehow, though, I don't think the original assigment anticipated that
>  sort() was available for use... *grin*

Iff sort() were available to us, then there's an embarassingly simply way
to solve this problem.

###
> >> def create_tag_array(L):
...     tag_array = range(len(L))
...     def mycmp(x, y):
...         return cmp(L[x], L[y])
...     tag_array.sort(mycmp)
...     return tag_array
...
> >> create_tag_array([1, 50, 0, 42])
[2, 0, 3, 1]
###

There are other really silly approaches to generate the sorted tag array,
and all of the silly approaches involve using sort().  So I'd rather hope
that the original assignment does not allow sort() at all.  *grin*


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Brian Christopher Robinson
Danny Yoo
Terry Carroll
Danny Yoo
Danny Yoo

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved