0
$\begingroup$

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.

$\endgroup$
3
$\begingroup$
Select[CountryData[], CountryData[#, "PhoneLines"]/CountryData[#, "Population"] >= 
   CountryData["USA", "PhoneLines"] / CountryData["USA", "Population"] &]

Gives:

{"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"}

EDIT

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"] &)]
$\endgroup$
  • $\begingroup$ +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] &] $\endgroup$ – Dr. belisarius Oct 24 '13 at 18:52
  • $\begingroup$ @Belisarius. I totally agree. $\endgroup$ – RunnyKine Oct 24 '13 at 18:53
  • 2
    $\begingroup$ Almost golfed cd = CountryData; r@x_ := cd[x, "PhoneLines"]/cd[x, "Population"]; Select[cd[], r@# >= r@"USA" &] $\endgroup$ – Dr. belisarius Oct 24 '13 at 18:57
  • $\begingroup$ @Belisarius. Nice! I like it much better. $\endgroup$ – RunnyKine Oct 24 '13 at 19:00
  • 1
    $\begingroup$ I wonder why the pope has so many phones $\endgroup$ – ssch Oct 24 '13 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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