Created
February 11, 2024 18:08
-
-
Save attheodo/4af0af103bf5943eb1e9d69789fb8a0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def count_genus_species(file_path): | |
genus_species = {} | |
total_species = 0 | |
total_genuses = 0 | |
with open(file_path, 'r') as file: | |
for line in file: | |
genus = line.split()[0] | |
species = line.split()[-1] | |
if genus in genus_species: | |
genus_species[genus].append(species) | |
else: | |
genus_species[genus] = [species] | |
total_genuses += 1 | |
total_species += 1 | |
average_species_per_genus = total_species / total_genuses | |
return total_genuses, average_species_per_genus | |
file_path = 'organisms.txt' | |
unique_genuses, average_species = count_genus_species(file_path) | |
print("Number of unique genuses:", unique_genuses) | |
print("Average number of species per genus:", average_species) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment