##
## python/examples/sort1.py
## David MacKay
### How to sort an array and keep track of which
### item went where.
a=[15,13,17,11]
### First make a new list containing the items, and indices.
c=list( [ a[i],i ] for i in range (len(a)) )
### c is:
### [[15, 0], [13, 1], [17, 2], [11, 3]]
c.sort()
c
### [[11, 3], [13, 1], [15, 0], [17, 2]]
Comments = """
Note that by default, sort will, if asked to compare
two sets, use the first element in the set.
For a good introduction to sort, see
http://www.amk.ca/python/howto/sorting/sorting.html.
"""
|