Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

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

Im playing around with CountryData and I want to pass it 2 lists as argument, listCountries = {...} and data = {"GDP","ExternalDebt"}

If I do CountryData[#, "GDP"]& /@ listCountries it works well, but I want something like

CountryData[#1, #2]& /@ {listCountries,data}

I read something about MapThread but can make it.

share|improve this question
Just did, it take the first 2 elements of the first list as input of #1 and #2 – Kafkarudo Jul 20 '14 at 21:55
up vote 3 down vote accepted

Consider these two lists:

listCountries = {
data = {

There are two cases: you want the GDP, population and area of each country in the first list. The most elegant solution I can think of is Outer:

Outer[CountryData, listCountries, data]

enter image description here

The other is that you want the GDP of Bangladesh, the Population of India and the area of Monaco; this can be achieved by either

CountryData @@ # & /@ Thread@{listCountries, data}

enter image description here


MapThread[CountryData, {listCountries, data}]
share|improve this answer
Yes!, that would do. That was more than awesome, I love this forum and how you people gave answers by teaching.Thank you guys! – Kafkarudo Jul 20 '14 at 22:30
@Öskå hey, thanks! – acl Jul 20 '14 at 22:35

Would this work for you? Using Map twice feels like the most intuitive approach to me.

listCountries = {"United States", "Mexico", "Canada"};
data = {"GDP", "ExternalDebt"};
Function[{country}, CountryData[country, #] & /@ data] /@ listCountries

Mathematica graphics

If you want to display the country next to its data, just modify your Function to include that information.

listCountries = {"United States", "Mexico", "Canada"};
data = {"GDP", "ExternalDebt"};
Function[{country}, Prepend[CountryData[country, #] & /@ data, 
   country]] /@ listCountries

Mathematica graphics

share|improve this answer
You can do Outer[{#1, CountryData[#1, #2]} &, listCountries, data] for the second bit. Outer is very flexible and well worth understanding. – acl Jul 21 '14 at 11:48
@acl Great tip! Thank you. – seismatica Jul 22 '14 at 3:56

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.