# Wolfram Mathematica

## 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]:=
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]:=
c1 = TakeSmallest[data[[All, 1]], 2]
Out[2]=

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

In[3]:=
c2 = TakeLargest[data[[All, 2]], 2]
Out[3]=

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

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