Wolfram Archive
Wolfram Programming Lab is a legacy product.
All the same functionality and features, including access to Programming Lab Explorations, are available with Wolfram|One.
Start programming now. »
Try it now »
(no sign-in required)

# Sort the Dinosaurs by Weight

Make a table of dinosaurs, with pictures, sorted by weight.

Run the code to get the list of dinosaurs known to the Wolfram Language:

This gets a list of dinosaurs and gives it the name dinosaurs. The output is automatically shortened because its very long:

dinosaurs = EntityList["Dinosaur"]

There are a lot of dinosaurs in the list:

Length[dinosaurs]

dinosaurs = EntityList["Dinosaur"]

Get a picture of a dinosaur. Try other dinosaurs:

Note: run the code in the previous step first.

This gives the second dinosaur in the list:

dinosaurs[[2]]

Each dinosaur has a wealth of information associated with it, which you can retrieve with EntityValue. Heres an image of the second dinosaur:

EntityValue[dinosaurs[[2]], "Image"]

EntityValue[dinosaurs[[1]], "Image"]

Get the name, an image, and the weight of a dinosaur. Try other dinosaurs:

Get the weight of the second dinosaur:

EntityValue[dinosaurs[[2]], "Weight"]

Get the name, an image, and the weight of the second dinosaur:

EntityValue[dinosaurs[[2]], {"Name", "Image", "Weight"}]

Sometimes data may be missing. The weight of the first dinosaur is not available:

EntityValue[dinosaurs[[1]], {"Name", "Image", "Weight"}]

EntityValue[dinosaurs[[2]], {"Name", "Image", "Weight"}]

Make a table of names, pictures, and weights of random dinosaurs. Run the code again to get different dinosaurs:

Get a random sample of 10 dinosaurs. Run the code again to get a different sample:

RandomSample[dinosaurs, 10]

Get the name, image, and weight of a random sample of dinosaurs:

EntityValue[RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}]

Format the dinosaur data as a table:

TableForm[ EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}]]

TableForm[ EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}]]

Sort the table by weight. Run the code again to get different dinosaurs:

Weights in the table are both single values, like , and ranges, like . To sort the table by weight, you have to first convert the ranges to single values. You can do that easily with a rule that replaces intervals with their average values (their means):

TableForm[ EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}] /. Interval[x_] :> Mean[x]]

Now you can sort the data by weight, which is the last element of each entry:

SortBy[EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}] /. Interval[x_] :> Mean[x], Last]

Make a table sorted by weight:

TableForm[ SortBy[EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}] /. Interval[x_] :> Mean[x], Last]]

TableForm[ SortBy[EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}] /. Interval[x_] :> Mean[x], Last]]

Share ItPut the dinosaur table online, where anyone can visit it.

Note: run the code in the very first step first to define dinosaurs.

Deploy the dinosaur table to the Wolfram Cloud, where anyone can visit it. The table updates each time its visited:

CloudDeploy[ Delayed[ExportForm[ TableForm[ SortBy[EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}] /. Interval[x_] :> Mean[x], Last]], "PNG"]], "Permissions" -> "Public" ]

Click the link in the output to visit the site. Refresh the page in your browser to get a new table.

Tell the world about your creation by sharing the link via email, tweet, or other message.

CloudDeploy[ Delayed[ExportForm[ TableForm[ SortBy[EntityValue[ RandomSample[dinosaurs, 10], {"Name", "Image", "Weight"}] /. Interval[x_] :> Mean[x], Last]], "PNG"]], "Permissions" -> "Public" ]