Wolfram Language

Core Language

Largest and Smallest Values

The functions TakeLargest, TakeLargestBy, TakeSmallest, and TakeSmallestBy provide simple ways of selecting elements from lists and associations by numerical order.

For each South American country, associate the life expectancy of its inhabitants and the gross domestic product (GDP) at purchasing power parity (PPP).

In[1]:=
Click for copyable input
data = EntityValue[ EntityClass["Country", "SouthAmerica"], {EntityProperty["Country", "LifeExpectancy"], EntityProperty["Country", "GDP", {"CurrencyUnit" -> "CurrentUSDollar", "PPP" -> "PPP"}]}, "EntityAssociation"]
Out[1]=

Use TakeSmallest to get the two countries with the lowest life expectancy.

In[2]:=
Click for copyable input
c1 = TakeSmallest[data[[All, 1]], 2]
Out[2]=

TakeLargest gives the two countries with the largest GDP at PPP.

In[3]:=
Click for copyable input
c2 = TakeLargest[data[[All, 2]], 2]
Out[3]=

Emphasize with colors these two sets of countries on a geographical map.

In[4]:=
Click for copyable input
GeoGraphics[{Red, Polygon[Keys@c1], Green, Polygon[Keys@c2]}]
Out[4]=

Related Examples

de es fr ja ko pt-br ru zh