Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering, *for which countries is the proportion of Phone line users to population greater than or equal to that of the United States?*

This is what I inputted below, but the list of countries seem too great.

countries=Last/@Take[Reverse[Sort[{CountryData[#,"PhoneLines"], #} & /@CountryData[]]], All]

Someone suggested I use "Select", but I have difficulties wording it.

share|improve this question
up vote 3 down vote accepted
Select[CountryData[], CountryData[#, "PhoneLines"]/CountryData[#, "Population"] >= 
   CountryData["USA", "PhoneLines"] / CountryData["USA", "Population"] &]


{"Barbados", "Bermuda", "BritishVirginIslands", "Canada", 
"CaymanIslands", "Cyprus", "FalklandIslands", "France", "Germany", 
"Gibraltar", "Greece", "Guernsey", "HongKong", "Iceland", 
"IsleOfMan", "Jersey", "Liechtenstein", "Luxembourg", "Malta", 
"Monaco", "Montenegro", "Niue", "NorfolkIsland", 
"SaintPierreMiquelon", "SanMarino", "Slovenia", "Sweden", 
"Switzerland", "Taiwan", "UnitedKingdom", "UnitedStates", 
"UnitedStatesVirginIslands", "VaticanCity"}


You can make CountryData Listable and use good 'ol Pick

SetAttributes[CountryData, Listable];    
Pick[CountryData[], CountryData[CountryData[], "PhoneLines"] / CountryData[CountryData[], 
"Population"], _?(# >= CountryData["USA", "PhoneLines"] / CountryData["USA", "Population"] &)]
share|improve this answer
+1 I sometimes hate Mma's verbosity cd = CountryData; pl = "PhoneLines"; po = "Population"; Select[cd[], cd[#, pl]/cd[#, po] >= cd["USA", pl]/cd["USA", po] &] – Dr. belisarius Oct 24 '13 at 18:52
@Belisarius. I totally agree. – RunnyKine Oct 24 '13 at 18:53
Almost golfed cd = CountryData; r@x_ := cd[x, "PhoneLines"]/cd[x, "Population"]; Select[cd[], r@# >= r@"USA" &] – Dr. belisarius Oct 24 '13 at 18:57
@Belisarius. Nice! I like it much better. – RunnyKine Oct 24 '13 at 19:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.