[Tutor] Bundle help!

Kent Johnson kent37 at tds.net
Tue Jun 26 16:11:36 CEST 2007


Sara Johnson wrote:
> Hi Kent,
>  
> I had a list to sort alphabetically (that included names and 
> percentages), then I had to apend that list to sort by the category 
> represented by the percentages.  I've tried to use something like:
>  
> mylist = [whatever...]
> mylist.append(whatever) and that doesn't seem to work.  Also with this 
> list being sorted by names and by percentages, and there are more than 
> just a few items, I don't think I could just list all of the items out as:
>  
> x = ['apple', 'pear', banana', 'orange'] ......an example from "For Dummies"
>  
> I've also looked at tuples and such.  This is probably something simple, 
> but what I've tried hasn't worked.  There isn't much on bundles in here 
> and I've looked at the python site too.  I got the alphabetical list to 
> work by creating a 'newlist.'  Then I tried 'newlist2' but I'm getting 
> strange results. 

I still don't know enough to help you much. It would help if you showed 
some real code and data. How are you storing the names and percentages? 
If you have a list of pairs of (name, percentage) then you should be 
able to sort it directly with the sort() method of the list. For example:

In [3]: data = [ ('Kent', 50), ('Sara', 80), ('Fred', 20) ]
In [4]: data.sort()
In [5]: data
Out[5]: [('Fred', 20), ('Kent', 50), ('Sara', 80)]

Use append() to add more data, then sort again to get it in order:
In [6]: data.append(('Joe', 90))
In [7]: data.sort()
In [8]: data
Out[8]: [('Fred', 20), ('Joe', 90), ('Kent', 50), ('Sara', 80)]

What is a bundle? I don't know of any Python meaning for that term.

Kent

PS Please use Reply All to reply to the list.


More information about the Tutor mailing list