Fwd: Sorting Countries by Region

patrick.waldo at gmail.com patrick.waldo at gmail.com
Fri Nov 16 23:15:29 CET 2007


Great, this is very helpful.  I'm new to Python, so hence the
inefficient or nonsensical code!

>
> 2) I would suggest using countries.sort(...) or sorted(countries,...),
> specifying cmp or key options too sort by region instead.
>

I don't understand how to do this.  The countries.sort() lists
alphabetically and I tried to do a lambda x,y: cmp() type function,
but it doesn't sort correctly.  Help with that?

For martyw's example, I don't need to get any sort of population
info.  I'm actually getting the number of various types of documents.
So the entry is like this:

Argentina	Food and Consumer Products	Food Additives	Color
Additives	        1
Argentina	Food and Consumer Products	Food Additives	Flavors 	        1
Argentina	Food and Consumer Products	Food Additives
General	                6
Argentina	Food and Consumer Products	Food Additives	labeling	        1
Argentina	Food and Consumer Products	Food Additives	Prohibited
Additives	1
Argentina	Food and Consumer Products	Food Contact	Cellulose	        1
Argentina	Food and Consumer Products	Food Contact	Food
Packaging	        1
Argentina	Food and Consumer Products	Food Contact	Plastics	        4
Argentina	Food and Consumer Products	Food Contact
Waxes	                1
Belize
etc...

So I'll need to add up all the entries for Food Additives and Food
contacts, the other info like Color Additives isn't important.

So I will have an output like this
          Food Additives    Food Contact
Argentina     10                7
Belize
etc...

Thanks so much for the help!



More information about the Python-list mailing list