Fwd: Sorting Countries by Region

J. Clifford Dyer jcd at sdf.lonestar.org
Sat Nov 17 09:34:48 EST 2007


On Sat, 2007-11-17 at 03:34 -0800, patrick.waldo at gmail.com 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 expected list", country
> 

This snippet fails because you want 'and' rather than 'or'.  In this
one, you test to see that country is not in EU, and if you have, say
'France' as your country, the first half evaluates false, so the or
tells it to try again with North America.  Lo and behold, france is not
in North America, so the second half returns true.  False or True
returns True, so your code prints "France is not in the expected list."

Cheers,
Cliff





More information about the Python-list mailing list