How long do animals live? This beautiful infographic (PDF1) by Alan Bernau Jr. shows the life span of animals from rodents to humans to sharks, showing how animal longevity ranges from a few years to 500 years or more. See where you lie in this list of 50 animals!
The properties of some things are described in a text file. Each line of the file describes one thing by two or more information fields that are separated by commas. The first field contains the unique name of the thing. The name itself never contains commas. The other fields contain a numeric value (an integer) for a specific property of the thing. The number of fields may differ from file to file, but all lines within the same file contain the same number of fields. The fields containing the numeric values are numbered from left to right, starting from zero.
For example, this file contains numeric values for four properties of some animals (data.txt2):
GIANT BARREL SPONGE,2300,17,16,2 COW,20,3,9,2 DOG,13,3,20,4 LOBSTER,50,7,10,1 GEODUCK,140,7,15,7 CHICKEN,10,7,22,-1 GREATER FLAMINGO,60,15,20,4 KOI,50,3,19,7 CHEETAH,10,7,15,2 ALDABRA GIANT TORTOISE,255,20,21,-4
Here, we see for example that the animal with the name KOI has value 50 in field 0 (the animal's life span), value 3 in field 1 (the number of letters in the animal's name), value 19 in field 2 (the number of letters in the animal's binomial name: Cyprinus rubrofuscus) and value 7 in field 3. Your task:
Write a function read_properties that takes the location (str) of a text file with the properties of some things. The function must return a dictionary (dict) that maps each name (str) from the file onto a tuple with the numeric values (int) for the thing's properties.
Write a function values that takes two arguments: i)
a sequence (list or tuple)
of
Write a function arrange that takes two arguments: i)
a list (list) of names (str)
and ii) the location (str) of a text file with
the properties of some things. The function also has a third optional
parameter field that may take a number
Write a function arranged with the same required and optional parameters as function arrange, except that the first parameter may take a collection (list, tuple or set) of names. The function must return a new list in which the given names are listed in the same order as with the function arrange.
The last three functions may assume that the names (first argument) all appear in the file (second argument), without the need to check this explicitly.
In the following interactive session we assume the text file data.txt6 to be located in the current directory.
>>> properties = read_properties('data.txt7')
>>> properties['CHICKEN']
(10, 7, 22, -1)
>>> properties['KOI']
(50, 3, 19, 7)
>>> properties['COW']
(20, 3, 9, 2)
>>> values(['CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER'], 'data.txt8')
[10, 50, 20, 13, 10, 50]
>>> values(('CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER'), 'data.txt9', field=1)
[7, 3, 3, 3, 7, 7]
>>> values(('CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER'), 'data.txt10', field=3)
[-1, 7, 2, 4, 2, 1]
>>> words = ['CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER']
>>> arrange(words, 'data.txt11')
>>> words
['CHEETAH', 'CHICKEN', 'DOG', 'COW', 'KOI', 'LOBSTER']
>>> arrange(words, 'data.txt12', field=1)
>>> words
['COW', 'DOG', 'KOI', 'CHEETAH', 'CHICKEN', 'LOBSTER']
>>> arrange(words, 'data.txt13', field=3, descending=True)
>>> words
['KOI', 'DOG', 'COW', 'CHEETAH', 'LOBSTER', 'CHICKEN']
>>> arranged(['CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER'], 'data.txt14')
['CHEETAH', 'CHICKEN', 'DOG', 'COW', 'KOI', 'LOBSTER']
>>> arranged(('CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER'), 'data.txt15', field=1)
['COW', 'DOG', 'KOI', 'CHEETAH', 'CHICKEN', 'LOBSTER']
>>> arranged({'CHICKEN', 'KOI', 'COW', 'DOG', 'CHEETAH', 'LOBSTER'}, 'data.txt16', field=3, descending=True)
['KOI', 'DOG', 'COW', 'CHEETAH', 'LOBSTER', 'CHICKEN']
What animal lives the longest?
The animal with the longest life span is biologically immortal: Turritopsis dohrnii17, also called the "immortal jellyfish". This tiny creature can essentially hit the reset button in its growth18, sexually maturing and then reverting to a sexually immature version of itself in a process called transdifferentiation19, or the practice of converting adult cells to another type of tissue. This process has been getting some intense study as researchers work on gene therapies for humans. (Who knows? Perhaps one day human beings will discover how to transdifferentiate cells like these jellyfish do.) While it might not be a specific number of years, it's clear that the immortal jellyfish has the longest life span of any animal.
A specific species of black coral — Leiopathes glaberrima20 — which is technically an animal and one of the longest-living organisms on the planet, grows at an intensely slow rate; a Hawaiian specimen was reported to have an age of 4265 (±44) years.
Giant barrel sponges21 — sometimes called "the redwoods of the ocean" — can live into the thousands as well, with one specimen living to 2300 years.
Reports have boasted of this old creature — nicknamed Ming — with some news outlets accusing scientists of killing it22 and other sources claiming that the resulting blowback was overblown23. The 507-year-old shelled creature died in 2006, but it would have lived in the era of wooden ships!
The Greenland shark hit the news as well24, as specimens were reported to be anywhere between 272 and 512 years old. They also don't reproduce until they're about 150 years old25.
Of course, animals are not necessarily the longest-living organism; that honor likely goes to a 5065-year-old plant, the bristlecone pine26. Of course, when you add in other factors, like biological immortality, it can definitely be difficult to rank the oldest organisms.
The shortest life span an animal has is only a day. The "winner" here is an insect, specifically the mayfly27, found near streams and lakes worldwide. A day in the life of a mayfly must be pretty intense!