Re: Sorting Countries by Region

2007-11-19 Thread martyw
nothing, Alan wrote: > On Nov 16, 8:28 pm, martyw <[EMAIL PROTECTED]> wrote: >> i would create a class to capture country information, e.g. > > > What is the advantage of this: > >> def __cmp__(self, other): >> if self.name < other.name: >> return -1 >> elif s

Re: Fwd: Sorting Countries by Region

2007-11-17 Thread J. Clifford Dyer
On Sat, 2007-11-17 at 03:34 -0800, [EMAIL PROTECTED] wrote: > #This seems to not work today and I don't know why > #for country in countries_list: > #if country not in REGIONS_COUNTRIES['European Union'] or not in > REGIONS_COUNTRIES['North America']: > #print "%s is not in the expecte

Re: Fwd: Sorting Countries by Region

2007-11-17 Thread Gabriel Genellina
En Sat, 17 Nov 2007 08:34:43 -0300, <[EMAIL PROTECTED]> escribió: > for i, country in countries_list: > if country in REGIONS_COUNTRIES['European Union']: > matrix.write(i+2, 1, country) > but I got "ValueError: too many values to unpack" Remove the i, and try again... -- Gabriel

Re: Fwd: Sorting Countries by Region

2007-11-17 Thread patrick . waldo
This is how I solved it last night in my inefficient sort of way and after re-reading some of my Python books on dictionaries. So far this gets the job done. However, I'd like to test if there are any countries in the excel input that are not represented, ie the input is all the information I hav

Re: Fwd: Sorting Countries by Region

2007-11-16 Thread Sergio Correia
About the sort: Check this (also on http://pastebin.com/f12b5b6ca ) def make_regions(): # Values you provided EU = ["Austria","Belgium", "Cyprus","Czech Republic", "Denmark","Estonia", "Finland"] NA = ["Canada", "United States"] AP = ["Australia", "China", "Hong Kong", "India

Re: Fwd: Sorting Countries by Region

2007-11-16 Thread patrick . waldo
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 al

Re: Sorting Countries by Region

2007-11-16 Thread Alan
On Nov 16, 8:28 pm, martyw <[EMAIL PROTECTED]> wrote: > > i would create a class to capture country information, e.g. What is the advantage of this: > def __cmp__(self, other): > if self.name < other.name: > return -1 > elif self.name > other.name: >

Re: Sorting Countries by Region

2007-11-16 Thread martyw
[EMAIL PROTECTED] wrote: > Hi all, > > I'm analyzing some data that has a lot of country data. What I need > to do is sort through this data and output it into an excel doc with > summary information. The countries, though, need to be sorted by > region, but the way I thought I could do it isn't

Fwd: Sorting Countries by Region

2007-11-16 Thread Sergio Correia
Just a few notes: 1) get_countries_list What is the purpose of that function? Besides a few errors (an argument named list, no value returned), it seems you just want to remove duplicates from a list called countries. You can do that transforming the list to a 'set'. new_countries = list( set(c

Sorting Countries by Region

2007-11-16 Thread patrick . waldo
Hi all, I'm analyzing some data that has a lot of country data. What I need to do is sort through this data and output it into an excel doc with summary information. The countries, though, need to be sorted by region, but the way I thought I could do it isn't quite working out. So far I can only